Sometimes you need to create a WCF service starting from a WSDL giving to you the specifications. It is a good practice and quite simple to do.

First of all, you need the SvcUtil.exe file. To find it and know what is about, just go here. You can just copy&paste it where you have the WSDL.

All you have is the WSDL file and the SvcUtil.exe. Open the command prompt and go to the WSDL location. Then, just run the command

svcutil.exe service.wsdl

IMPORTANT: if the WSDL referes to one or more xsd file, you have to specify it when run the command:

svcutil.exe service.wsdl first.xsd second.xsd ......

If you don’t specify the xsd file(s), you can get this error:

Error: Cannot import wsdl:portTYpe
Detail: There was an error importing a wsdl:portType that the wsdl:binding is dependent on.
XPath to wsdl:portType: //wsdl:definitions[@targetNamespace='......']
XPath to Error Source: //wsdl:definitions[@targetNamespace='.....']


Error: Cannot import wsdl:binding
Detail: There was an error importing a wsdl:portType that the wsdl:binding is dependent on.
XPath to wsdl:portType: //wsdl:definitions[@targetNamespace='......']
XPath to Error Source: //wsdl:definitions[@targetNamespace='.....']


Error: Cannot import wsdl:port
Detail: There was an error importing a wsdl:binding that the wsdl:port is dependent on.
XPath to wsdl:binding: //wsdl:definitions[@targetNamespace='.....']
XPath to Error Source: //wsdl:definitions[@targetNamespace='....']


Generating files...
Warning: No code was generated.
If you were trying to generate a client, this could be because the metadata documents did not contain any valid contracts or services
or because all contracts/services were discovered to exist in /reference assemblies. Verify that you passed all the metadata documents to the tool.

Warning: If you would like to generate data contracts from schemas make sure to use the /dataContractOnly option.
Advertisements