Import web service references in .NET

Posted by Andrea on 2010-06-09 13:13
You may need to consume Web services from  client applications.
Visual Studio provides tools for generating proxy classes, which in this case, however, may be ineffective.

A common workaround implies the command prompt tool wsdl.exe included within the NET Framework 2.0 SDK.
This tool accepts the path to a WSDL file and generates the proxy class automatically.
"C:\Program Files\Microsoft SDKs\Windows\v6.0A\bin\wsdl.exe"_
  "C:\ServiceTest.wsdl" /n:MyNameSpace.MyServices /o:"C:\ServiceTest.cs" /l:CS

In this example we are specifying:
  • The path of the WSDL
  • "/n" - the target namespace of the proxy class
  • "/o" - the path of output files
  • "/l" - the target language

A complete list of options is available at this Url:
http://msdn.microsoft.com/en-gb/library/7h3ystb6%28v=VS.80%29.aspx

If you plan to generate more files related to classes in the same namespace, is useful to remember that some objects are implicitly declared many times, these duplicates must be removed manually.

Related articles:
Testing a Web service with a proxy class