SvcUtil.exe – Quick Trick

When using SvcUtil.exe to generate proxy for a Web Service which references a .XSD, you might face this error very often:

Error: Cannot import wsdl:portType
Detail: An exception was thrown while running a WSDL import extension: System.ServiceModel.Description.XmlSerializerMessageContractImporter
Error: The attribute tokenType is missing.
XPath to Error Source: //wsdl:definitions[@targetNamespace='http://fw3rd.services.telefonica.es/services/IDP']/wsdl:portType[@name='TokenTranslation']

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='http://fw3rd.services.telefonica.es/services/IDP']/wsdl:portType[@name='TokenTranslation']
XPath to Error Source: //wsdl:definitions[@targetNamespace='http://fw3rd.services.telefonica.es/services/IDP']/wsdl:binding[@name='TokenTranslationSOAP']

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='http://fw3rd.service
s.telefonica.es/services/IDP']/wsdl:binding[@name='TokenTranslationSOAP']
XPath to Error Source: //wsdl:definitions[@targetNamespace='http://fw3rd.services.telefonica.es/services/IDP']/wsdl:service[@name='TokenTranslation']/wsdl:port[@name='TokenTranslationSOAP']

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.

It took me plenty of time to figure out the problem. But actually, the solution to it is simple. The SvcUtil.exe requires you to pass the .XSD files as parameters along with the input. It does not take the .XSD by itself even if you have given referenced it in the WSDL document.

The following syntax will fix the problem.

> SvcUtil.exe <WSDL Path> <.XSD Path> [If you have multiple XSDs referenced, give all of them separated by space]