Creating a Proxy class for a WebService in .NET

The easiest way to create a WebService Client in .NET is right clicking in the Project you want the reference and chosing Add a Service Reference.

Although that is quite easy and simple, there are some cases where you might prefer only the proxy class that calls the WebService. For instance, when you don’t want to mess up with the Web.Config file or load the URL from somewhere else other than a config file, i.e. the registry, or when you want to create a DLL to use in another project. For those cases you can open a Visual Studio Command Prompt from the Start Menu and use the command line below:

wsdl /l:CS /protocol:SOAP http://localhost/WebServiceTest/MyWebService.asmx?WSDL

The first parameter tells the wsdl.exe to use the language CS (CSharp) and the second tells that we are going to use the SOAP protocol. The third is the URL of the WebService – it can be a file path as well.

There are more parameters you can pass in besides those used in here. You can add /? to see those other parameters.

Any comments or opinions about this post will be welcome.