tags:

views:

24

answers:

2

Hi,

I am new to WCF, want to know what difference it make sync call or async call, it will be really helpful if some one will explain with example

Thanx

A: 

Async call from the client is same as any ohter async operation in .NET Framework. When you make sync call from a thread to the WCF service the thread will hang on. It means thread will not be able to do any other work until the service call returns response or exception. In contrast the async call will run in separate thread (created by framework) so your main thread will be able to continue in operation and it will be notified about completion of async call by callback (event).

So suppose that you have WinForms application as WCF client and you want to call WCF service. If you make a sync call which will take several seconds to complete your application will hangs on for this processing time = user will not be able to do anything with application (only kill it from task manager). But if you use async call it will be fully interactive because async operation will be handled by background thread. So async operations are suitable for interactive solutions or if you need to do multiple operations in parallel.

For example check this How to article from MSDN.

Just for completness I described difference between sync and async calls = synchronous and asynchronous processing on the client. WCF also supports sync and async operations = synchronnous and asynchronous processing on the server.

Ladislav Mrnka
A: 

WCF has async support baked in. There may be various scenarios for use of async calls.

In case your application needs to make a WCF call which in turn does some time consuming process, then it might be better to make a async call. This will give control to the user immediately so that the application does not appear hung. As soon as the background WCF call finishes, it would let the application user know that is is done.

Let's say you have a WCF which inserts some rows into a table. Assume that the WCF asks for tablename and the rows to be inserted as arguments. So if you need to call the WCF 3 times to insert rows into 3 separate tables, perhaps it would be better to start 3 async calls which can work in parallel instead of sequentially inserting the rows in the 3 tables one by one.

Get some good reading at: http://www.codeproject.com/KB/WCF/WCFConcurrency.aspx

Saurabh Kumar