SvcUtil Essentials: Asynchronous Proxy Methods

26. July 2007 10:00

This is the next post in my mini-series on some highlights of svcutil.

One of the most common questions I am asked that leads into a conversation about svcutil is "How do I generate a proxy with asynchronous methods?"  If you have worked very much with ASP.NET web services (ASMX), you are probably used to seeing methods in your proxy that are prefixed with Begin and End.  For example, let's say that your web service has a method named Foo.  A proxy generated by the wsdl utility (or even directly by Visual Studio) will contain a Foo method as well as BeginFoo and EndFoo methods.  If you execute the Foo method, the web service operation is invoked synchronously.  However, you can leverage the BeginFoo and EndFoo methods to asynchronously invoke the corresponding web service operation.

If you are accustomed to using these asynchronous methods, you will quickly find them to be missing from a WCF proxy that gets generated by Visual Studio.  For whatever reason, the asynchronous methods are no longer generated by default.  There is a specific switch in svcutil that is required in order to output the asynchronous methods.  Unfortunately, the switch isn't used when generating a proxy via Visual Studio.  Fortunately, it is quite simple to do via svcutil.

All that is required is adding an additional switch: /async or /a for short.

Here is an example command that will generate asynchronous methods from a service that is already running:

svcutil /t:code http://localhost/myService /out:Proxy.cs /config:Proxy.config /async

Here is a command that will generate asynchronous methods from local wsdl and xsd files:

svcutil /t:code *.wsdl *.xsd /out:Proxy.cs /config:Proxy.config /async

Comments are closed

About Me

I'm a passionate software developer and advocate of the Microsoft .NET platform.  In my opinion, software development is a craft that necessitates a conscious effort to continually improve your skills rather than falling into the trap of complacency.  I was also awarded as a Microsoft MVP in Connected Systems in 2008, 2009, and 2010.


Can’t code withoutThe best C# & VB.NET refactoring plugin for Visual Studio
Follow jeff_barnes on Twitter

View Jeff Barnes's profile on LinkedIn

 

Shared Items

Disclaimer

Anything you read or see on this site is solely based on my own thoughts.  The material on this site does not necessarily reflect the views of my employer or anyone else.  In other words, I don't speak for anyone other than myself.  So, don't assume I am the official spokesperson for anyone.