TaskWsdlImportExtension–a hidden gem in the C# vNext async CTP samples

NoWhen I first heard about the new async functionality in C# at PDC 2010 last week, my immediate reaction was; how can this be used to ease the development of asynchronous WCF/WF services (and clients).

Well, it turns out that someone on Microsoft has thought about the same thing; in the samples that accompanies the recently released C# async CTP, there’s a sample named (C# WCF) Stock Quotes. This picked my interest, and lo and behold; when I opened up the solution, I immediately noticed the TaskWsdlImportExtension.

Basically, the project contains an extension to WCF that plugs into the WSDL import pipeline, and customizes the output of the generated code you get when you use the Add Service Reference functionality (ASR) in Visual Studio. Now, I have to admit that I’m not the greatest fan of ASR and I normally write my own clients instead, but you can get the extension importer to work with svcutil.exe on the command line as well by pointing to a app.config wiring up the extension with the /SvcutilConfig:<file> parameter (or creating file named exactly Svcutil.exe.config in the same directory as you are doing the import in). More information can it can be found in the WSDL Import section in this MSDN article.

With this extension wired up, the C# client proxy code that is generated looks like this:

Now, that looks kinda complicated – and it is, but you don’t really need to understand what is to start using it. Since System.Threading.Tasks is a new feature in .NET 4.0, there is really nothing that stops you from using the extension right away – it doesn’t rely on the async/await keywords that we’ll see in C# vNext!

Now, if Microsoft hasn’t thought of it already; it would be nice to see a similar way of using System.Threading.Task/C# async in the implementation as well. I’m guessing it wouldn’t be too hard to create and it would probably involve a custom dispatcher invoker that would replace the default dispatcher in WCF (hint; I’m looking into this now).

Be Sociable, Share!

  • https://me.yahoo.com/a/l7l3lM5.kJPQjBHVpjFMMJbVybKJLdDPlPGPCA--#fff83 chadbr

    It would be even better if Task was available in Silverlight…

  • Anonymous

    Better than what? yes, it would be nice if System.Threading.Tasks were available in Silverlight too, but the lack of the functionality doesn’t make it any less useful in .NET 4.0…

  • https://me.yahoo.com/a/l7l3lM5.kJPQjBHVpjFMMJbVybKJLdDPlPGPCA--#fff83 chadbr

    Couldn’t agree more… but I have to do both so – it’s easier to have 1 impl that works on both than 2 impls (one for desktop, one for web) – I’m just grouchy :)

  • https://www.google.com/accounts/o8/id?id=AItOawmddDL_Y6zAvlVRsRuyJ9x8U62V6XmK1ug Stephen Cleary

    They’re planning to allow Task-based async server implementations in WCF vNext: http://blogs.msdn.com/b/endpoint/archive/2010/11/13/simplified-asynchronous-programming-model-in-wcf-with-async-await.aspx