wcf – Jay R. Wren – lazy dawg evarlast http://jrwren.wrenfam.com/blog babblings of a computer loving fool Wed, 15 Feb 2017 02:57:57 +0000 en-US hourly 1 https://wordpress.org/?v=4.7.2 WCF Async Without Changing The Contract http://jrwren.wrenfam.com/blog/2011/03/16/wcf-async-without-changing-the-contract/ http://jrwren.wrenfam.com/blog/2011/03/16/wcf-async-without-changing-the-contract/#comments Thu, 17 Mar 2011 02:58:30 +0000 http://jrwren.wrenfam.com/blog/2011/03/16/wcf-async-without-changing-the-contract/ Continue reading "WCF Async Without Changing The Contract"]]> Someone asked a group of people recently about how to prevent overloading a WCF service that gets blocked. It sounded like the WCF service was getting called a lot and this was causing many threads to get created to service all of the requests, but nearly all of those threads were blocked handling some IO requests.

I vaguely recalled something about WCF async and I suggested this person look into that. I even looked up the AsyncPattern=true property and value for the OperationContract attribute, but the person didn’t want to break the contract. I was pretty sure that this change was only a server side change and that it wouldn’t break any contract, but I wasn’t 100% sure.

Today I confirmed that I was right. The generated WSDL does not change when you change your contract from something like this:

[ServiceContract]

public interface IOrderService

{

[OperationContract]

Order[] GetOrders(int numOrders);

}

To something like this:

[ServiceContract]

public interface IOrderService

{

[OperationContract(AsyncPattern=true)]

IAsyncResult BeginGetOrders(int numOrders, AsyncCallback callback, object state);

Order[] EndGetOrders(IAsyncResult result);

}

If you want to convert existing WCF services to server-side async style, you can do so without your clients ever knowing. (There may be a caveat when using a ChannelFactory, see the docs.)

The MSDN docs are pretty good. An overview here http://msdn.microsoft.com/en-us/library/ms730059.aspx some better details here http://msdn.microsoft.com/en-us/library/ms731177.aspx

Dan Rigsby had some blog posts from when these features were rolled out, but beware his examples, he keeps a sync version and an async version, which is not strictly required. http://www.danrigsby.com/blog/index.php/2008/03/26/async-operations-in-wcf-iasyncresult-model-server-side/

Finally, Wenlong Dong’s blog gives great reasons why you would want this and even goes as far as suggesting using the async version of the datareader for async database access. http://blogs.msdn.com/b/wenlong/archive/2009/02/09/scale-wcf-application-better-with-asynchronous-programming.aspx

]]>
http://jrwren.wrenfam.com/blog/2011/03/16/wcf-async-without-changing-the-contract/feed/ 1