Tuesday, December 11, 2012

Svcutil and xsd imports

When wanting to generate a client proxy through svcutil, I always forget the exact syntax when I have a WSDL with xsd imports - i.e. when you get the syntax wrong (or don't have the xsd's included in the command line at all) you'll no doubt get the following errors:

Error: Schema with target namespace 'http://namespace/v1' could not be found.

Error: Cannot import wsdl:portType. 

etc...

The basic command line syntax is svcutil [location of wsdl] [location of xsds] - where if there are multple xsds, then the locations are seperated by a space, e.g:

svcutil C:\MyWsdl.wsdl C:\Folder1\Xsd1.xsd C:\Folder2\Xsd2.xsd

A lot of the wsdls I build share xsds, which are in different locations, however some share the same location - but I just need to specify the location and then specify a wildcard  *.xsd, which will result in all xsd files in the folder being picked up by svcutil - e.g.

svcutil C:\MyWsdl.wsdl C:\Folder1\*.xsd C:\Folder2\*.xsd