Thats Great, but…

Task based like we just saw is available only from .NET 4.5 and it requires that service itself will implement the method using Tasks – wither by using the async keyword or by actually returning a Task.

It turns out that youc can still add the Task asynchronicity even if the Service side does it’s work synchronously.

All you ned to do is to add an interface with the Async methods and specify that the Async methods are pointing to the synchronous method.

in the example i added a method with the name Minus. The method is synchronous and the Calculator service didnt had to do anything special.I created a new interface that declare an Async method and method was decorated with the OperationContract attribute, and i specified that the Action of that method is actually the Synchronous version of Minus, and i also set the ReplyAction to be the ReplyAction of Synchronous version of Minus.

On the client side i changed the App.Config so that the endpoint is now looking for ICalculatorAsync interface when talking to the Service.

Now, when the client code create a channel, what is created is a proxy that implement the ICalculatorAsync interface, and client side WCF client is smart enough to understand how the to work against the Task based version.

Summary

Sometimes you find yourself with a need to work with some synchronous service, with WCF you have the power to still enjoy the benefits of async-await and Task based method without the need to change the service side. The method i showed enable you to create the Async interface even on the client side and everything will work beutifully.