Example 33 : Generating C# From the WSDL

Printer-friendly version

Microsoft provides a tool to generate stub source code from WSDL files named wsdl.exe. You can use it to generate C# code by default. However, you can also use it to generate VB.NET code (using the /language:vb command line parameter) or other languages.

 

Step 1. Ensure wsdl.exe is in your PATH environment variable, and that your Internet connection is available. You can usually find the wsld.exe tool in C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\Bin

Step 2. Generate the C# code by issuing the WSDL.EXE tool from the command prompt (see below).
 
Step 3. Due to a bug in WSDL.EXE, after generating 3.x code you'll need to change the type of "SearchResult.recordsField" – it types it as "string[][]" whereas it should be "string[]". If you don't do this step, you'll get this error:
 
Unable to generate a temporary class (result=1). error CS0029: Cannot implicitly convert type 'string' to 'string[]'
 
wsdl.exe /sharetypes /out:generated.cs 
 http://www.metapack.com/devcentre/sites/default/files/wsdl/3.x/AllocationService.wsdl
 http://www.metapack.com/devcentre/sites/default/files/wsdl/3.x/ConsignmentSearchService.wsdl
 http://www.metapack.com/devcentre/sites/default/files/wsdl/3.x/ConsignmentService.wsdl
 http://www.metapack.com/devcentre/sites/default/files/wsdl/3.x/ConsignmentTrackingService.wsdl
 http://www.metapack.com/devcentre/sites/default/files/wsdl/3.x/DebugService.wsdl
 http://www.metapack.com/devcentre/sites/default/files/wsdl/3.x/InformationService.wsdl
 http://www.metapack.com/devcentre/sites/default/files/wsdl/3.x/SetupService.wsdl
 http://www.metapack.com/devcentre/sites/default/files/wsdl/3.x/ManifestService.wsdl