Tuesday, January 10, 2012

SvcUtil and imports

Recently I had to generate a client proxy for a WCF service. As the service was being developed by another team and was running as a local service on their machines, the only thing they could give me to generate my client proxy were the generated wsdl and xsd files of the service. I had no access to the actual service.

So, I started up svcutil.exe and tried to generate the client proxy. This didn't work as expected, however. Since the wsdl file generated by WCF uses imported xsd files. When you run svcutil with access to the actual service, the tool automatically downloads the necessary extra xsd files for you. When, however, you don't have access to the WCF service, you need to specify the extra xsd files in your call to svcutil.

So the following call:

SvcUtil.exe /noconfig the_wsdl_file.xml

Which gives errors on wsdl:portType and wsdl:binding, can be changed to this:

SvcUtil.exe /noconfig the_wsdl_file.xml first_import.xsd second_import.xsd

And that second call works just fine. No errors, my client proxy got nicely generated.

Another must-know about svcutil is that when you want to have your list types generated as a generic list in stead off an array type, you need to use the following extra switch:

/collectionType:System.Collections.Generic.List`1

Beware of the quote there, it's a tricky one. And you do need the entire namespace as well or svcutil won't recognize the type.