Wanted to write up a post on whats the difference between "auto" opening a WCF Channel and explicitly calling "Open" on it. Michael Maruchek posted a detailed and well explained post at http://blogs.msdn.com/mjm/archive/2006/11/13/auto-open-part-1.aspx. Waiting for part 2.
Since Micheal did such a wonderful job of explaining the design I just wanted to illustrate the behavior with a sample app.
I have a simple contract that has a Sync and Async version and the client will invoke a operation on the async contract 10 times. Lets see the difference in actual behavior when the channel is auto opened and explicitly opened.
First the contract definitions.
[
{
}
[ServiceContract]
public interface ISyncService
Here is the contract implementation. Notice the multiple concurrency that should allow concurrent processing of multiple messages.
#region
Thread
#endregion
channel.BeginSayHello(i, SayHelloCallback, channel);
Issued all asynchronus requests. Waiting for them to complete.SayHello invoked with Id: 0SayHello invoked with Id: 1SayHello invoked with Id: 2SayHello invoked with Id: 3SayHello invoked with Id: 4SayHello invoked with Id: 5SayHello invoked with Id: 6SayHello invoked with Id: 7SayHello invoked with Id: 8SayHello invoked with Id: 9All async requests completed
As you can see no matter how many times the client is run the server processes all the async invocations sequentially and in the order it was issued. This defeats the purpose of issuing async calls and having multiple concurrency mode on the server.
Lets see the output when the channel is explicitly opened. I just added the following line before issuing the requests.
((
Output is:
Issued all asynchronus requests. Waiting for them to complete.SayHello invoked with Id: 0SayHello invoked with Id: 2SayHello invoked with Id: 4SayHello invoked with Id: 5SayHello invoked with Id: 1SayHello invoked with Id: 3SayHello invoked with Id: 7SayHello invoked with Id: 6SayHello invoked with Id: 8SayHello invoked with Id: 9All async requests completed
As you can see the output is truly async and truly concurrent.
Maheshwar Jayaraman