简体   繁体   中英

Choosing design pattern to consume SOAP webservice in a C# client application

I have a C# client application and I need to consume two SOAP webservices that are hosted in external webMethods environment that exposes same functions (same name, same parameters and datatypes) ie

Web Service 1 - ManualLoadProduction

Function 1 - LoadMontlyData(string Month)

Function 2 - LoadYearlyData(string Year)

Web Service 2 - ManualLoadConsumption

Function 1 - LoadMontlyData(string Month)

Function 2 - LoadYearlyData(string Year)

I have added web reference for both of the web services in my C# solution. I can simply call the functions separately, however, I need build a layered solution. How should I design/implement the solution

You have an interface that you can use through out you application. This allows the consuming code to be dependent on a contract rather than a specific implementation.

public interface IServiceWrapper{

    Data  LoadMontlyData(string Month);
    Data LoadYearlyData(string Year);
}

Here is one implementation for ManualLoadProduction wrapper. Wrapping the service method allows you to wrap other functionality around the service calls, such as extra validation or object mapping.

public class ManualLoadProductionWrapper: IServiceWrapper{

      public Data LoadMontlyData(string Month){
         //implementation calls service method
      }

       public Data LoadYearlyData(string Year){
         //implementation calls service method
      }
}

public class ManualLoadConsumption: IServiceWrapper{

      public Data LoadMontlyData(string Month){
        //implementation calls service method
      }

      public Data LoadYearlyData(string Year){
       //implementation calls service method
      }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM