Saturday, April 23, 2011

svcutil.exe with a wsdl on the local disk

@YaronNaveh

svcutil.exe is a command line to generate wcf proxies from wsdl files (and more).

for example the following command:

$> svcutil http://localhost/MyServices/Service.svc?WSDL

will generate Service.cs which is the proxy you can add to your project.

Sometimes the wsdl file is not on a url but on the local disk. In theory this should work:

$> svcutil c:\services\calc.wsdl

In practice this would work only if the wsdl does not reference other wsdl or xsd files (even if their relative reference is correct). The same would work with "add service reference" in VS so not sure why it fails here. One solution is to explicitly specify all the referenced schema files in the command:

$> svcutil" c:\services\calc.wsdl" "c:\person.xsd c:\units.xsd"

This usually works but requires manual work and is not always desired when a large number of references is used.

An alternative would be to upload the wsdl and the references to a web server and svcutil from there. If you have iis on your dev machine this is actually pretty simple:

1. copy the wsdl root folder to a subfolder under c:\inetpub\wwwroot
2. run

$> svcutil http://localhost/root/calc.wsdl

That's all, no need to specify all files. svcutil works well from url locations. Do not forget to remove the wsdl folder after so your iis folder would stay clean.

@YaronNaveh

What's next? get this blog rss updates or register for mail updates!

6 comments:

tatman said...

That's very clever. :)

DragonMan said...

Awesome!

Chris said...

Can you not just put all of your wsdls/xsds in the same folder and use *.wsdl *.xsd? This will then look at all WSDL and XSDs in the directory for the references.

Chris said...

Can you not just put all of your wsdls/xsds in the same folder and use *.wsdl *.xsd? This will then look at all WSDL and XSDs in the directory for the references.

Yaron Naveh (MVP) said...

I believe this will also work

Taha Zubair Ahmed said...

your blogs clear me some points, if the new service.cs created by wsdl/svcutil command how would i utilize the code means the command returns me a very long service.cs file

Please see reference:
http://forums.asp.net/t/1831357.aspx/1?create+service+skelton+from+WSDL+file