Saturday, March 9, 2019

SvcUtil to generate Proxy from the WSDL file

To generate the proxy from the wsdl file, use the svcutil.exe. You can access it either by navigating via command prompt to the physical path of the file (Example: C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin)  or simply by using Visual Studio Command Prompt

svcutil.exe ProvideShopping.wsdl  /Language=c# /t:Code /out:Shopping.cs /config:Shopping.config

You might get an error in case you don't specify the xsd files along with the WSDL file

Example errors might be:

Error: Cannot import wsdl:portType
Detail: An exception was thrown while running a WSDL import extension: System.ServiceModel.Description.dataContractSerializerMessageContractImporter
Error: Schema with target namespace "http://someUrl" could not be found 

Error: Cannot import wsdl:binding
Detail: There was an error importing a wsdl:portType that the wsdl:binding is dependent on.

Add the related .xsd files to the folder which contains the wsdl and run command again

svcutil.exe ProvideShopping.wsdl commontypes.xsd ShoppingQ.xsd ShoppingS.xsd edist.xsd bis.xsd structures.xsd System1.xsd  /Language=c# /t:Code /out:Shopping.cs /config:Shopping.config

Please note if you are not interested in going through the generated code, but you only want a service reference in Visual Studio, then simply provide the path to the wsdl file location in your computer. There also you have to have the related .xsd files in the folder containing the wsdl or else you will get an error when Visual Studio generates the service reference for you.