Let's say we have developed a simple web service, a SOAP based service which performs some CRUD operations. One way to inherit its features in our main project is to add a web reference. It will create a discivery file and we will be able to access all the public methods of the service. But what if we need to consume the same web service in multiple projects? Moreover, service can be deployed on a different server from the project if we are following a layered architecture. 

        Suppose if there are new web methods added to the service or any such like situation mentioned above, we have to get the update from serivce reference again and again.

        In order to avoid that, we need to create a proxy class which will act as a bridge between the actual hosted web service and the proxy which we use.

        .NET Framework provides us WSDL.exe which helps us to generate proxy class for us using command line.

        If you look into MSDN, it says "The Web Services Description Language tool generates code for XML Web services and XML Web service clients from WSDL contract files, XSD schemas, and .discomap discovery documents."

wsdl [options] {URL | path}

Example: In the command prompt, we need to write below command to
generate proxy class.

C:\Program Files (x86)\Microsoft SDKs\Windows\v8.0A\bin\NETFX 4.0 Tools>wsdl.exe /language:CS /n:"YourNamespace" /out:YourLocaDrivePath\ClassName.cs http://localhost:49461/MyService.asmx
  1. First is the local path where WSDL.exe resides.
  2. Specify language CS or VB as required.
  3. Give your class namespace.
  4. Provide your local drive path where you want proxy class to be generated.
  5. Give name to your class.
  6. Fianlly, provide the serivce address.
  7. Hit enter, it will generate the proxy class.

Hope this post is helpful.


blog comments powered by Disqus