Monday, July 02, 2007

Generating client code for a WCF service

Sometimes it is good to have a distributable proxy code for a WCF service prior it's been deployed and it is not possible to generate a client proxy through a wizard. There is a nice little utility SVCUTIL.EXE, which comes with WCF. I've seen it located under C:\Program Files\Microsoft SDKs\Windows\v6.0\Bin and Program Files\Microsoft Visual Studio 8\Common7\IDE folders. This utility allows to generate client proxy class and configuration template from a compiled WCF service library or executable.

First run utility against a compiled service code to generate metadata documents:
svcutil.exe MyService.dll.
It will generate a whole bunch of XSD and WSDL files. The next command:
svcutil.exe *.wsdl *.xsd /language:c#
will generate MyService.cs class - strongly-typed client proxy (guaranteed against the weird WCF proxy generation in Win App :), and output.config file - client endpoint and binding configuration.

These tricks are better described in the utility help than on Internet and it took me a while to figure out, so I decided to share it.

1 comment:

Chris Barrow said...

Sweet. That will save a lot time. Glad someone is looking into these things, because it is not like Microsoft has great documentation for .net 3.0.

© 2008-2013 Michael Goldobin. All rights reserved