Asynchronous WCF service invoke with C# 5.0 Async And Await

In most of the scenarios, We would like to invoke the WCF service asynchronously, especially if service takes a long execution time. If we are consuming the WCF service from WPF or Silverlight Application (or any other application) , We would not like to block the main thread by invoking the WCF service in a synchronous manner.

Traditionally, in a Async programming we have to separate the code for service invocation and result collection.Also, there is a overhead of context synchronization if your service call is on worker thread and UI running on Main thread (As in WPF applications). Although there are alternatives to fix the issues, C# 5.0 provides a clean alternative.

C# 5.0 Async and Await feature provides a cleaner way to provide asynchronous effect while code resembles more or less like an synchronous call. The heavy lifting and context synchronization overhead will be taken care by the C# 5.0 compiler.

In this example I will demonstrate, how to invoke a WCF service using C#5.0 Async and Await feature.


Abhishek is a software architect, developer and Pluralsight author. He is very passionate about working with data especially in the field of machine learning. He has authored several courses on machine learning which are available on Pluralsight. He has been involved in several software development projects, which involves various machine learning techniques. His work focuses on architecting and developing applications especially in the area of monitoring, optimization, pattern recognition, and fault detection. His professional interests include software design patterns, agile practices, and various technologies such as WCF, WF, WPF, Silverlight, SQL Server, Entity Framework and ASP.NET MVC. He is also a Microsoft Certified Professional (HTML5, Javascript, CSS3).

Tagged with: , , , , , ,
Posted in C#
One comment on “Asynchronous WCF service invoke with C# 5.0 Async And Await
  1. […] If you are using .NET framework 4.5+, there is even easier way to have async pattern in your code. You can go to my earlier blog post “Asynchronous WCF service invoke with C# 5.0 Async And Await” […]

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

About Me

Software Architect, Developer & Pluralsight Author

Software Architect, Developer & Pluralsight Author, Twitter Handle :

Enter your email address to follow this blog and receive notifications of new posts by email.

Join 116 other followers

The opinions expressed herein are my own personal opinions and do not represent my current or previous employer's view in anyway.
Live Feed
%d bloggers like this: