Create C# SOAP Proxy classes with Microsoft wsdl tool


Steps to create C# SOAP Proxy classes with Microsoft wsdl tool

For developing apps that support service reference (e.g. UWP apps), one can consume web services defined by WSDL files by adding a service reference in VS and using the generated proxy classes.  The approach requires the platform supports namespace System.ServiceModel which inner working is quite convoluted, so it is rigid, hard to customize to accommodate any special situation, especially, some authentication method. 

Another approach is generating relevant classes from WSDL files and construct SOAP messages with basic XML serialization and HTTP request classes without using System.ServiceModel at all, hence making it application to many platforms.  One can make some general SOAP and serialization methods that can be used by all SOAP requests practically, but hand-crafting every method corresponding to each of hundreds or thousands of requests defined in multiple WSDL files is impractical.  A viable approach is using VS to generate the proxy classes in Reference.cs, and adapt that file for general use in following steps:

  1. Adding a service reference in VS. One may add on WSDL URL first, then edit the MetadataSources tag of Reference.svcmap to add multiple WSDL URLs, and update the reference.
  2. Comment out all [System.ServiceModel.xxxAttribute(...)]
  3. Comment out all [return: System.ServiceModel.MessageParameterAttribute(Name="...")]
  4. Remove all references to System.ServiceModel.IClientChannel
  5. Create methods to send and receive SOAP messages.  There are different ways to do it.