Welcome to MSDN Blogs Sign in | Join | Help

Wenlong Dong's Blog


WCF/WF performance
WCF for the web
ASP.NET Async Pages vs Async WCF Service Operation

In Dmitry’s blog, he mentioned about how to write ASP.NET async pages with ASP.NET 2.0. Basically, the server page can handle the request asynchronously without blocking the request thread and the server thread can be returned to the thread pool to handle other requests.

 

WCF is quite flexible in supporting asynchronous programming. Actually the client and the service can use any pattern (sync or asnc) in their own way to perform the same operation. For example, you can use the following service contract with an async operation in it:

[ServiceContract(Namespace = "http://tempuri.org", Name = " HelloService")]

interface IHelloService

{

    [OperationContract(IsOneWay = false, AsyncPattern = true)]

    IAsyncResult BeginHello(string text, AsyncCallback callback, object state);

    string EndHello(IAsyncResult result);

}

This allows you to implement the service operation in the same way as ASP.NET async pages.

 

On the client side, you can access the service either from an async call or a sync call. For example, you can have a sync client to access the above async service operation with the following client contract:

[ServiceContract(Namespace = "http://tempuri.org", Name = "HelloService")]

interface IHelloService

{

    [OperationContract(IsOneWay = false)]

    string Hello(string text);

}

 

The sample code is attached for download.

 

Posted: Sunday, May 07, 2006 5:37 AM by wdong
Filed under:

Attachment(s): AsyncHello052006.zip

Comments

mattonsoftware.com said:

The following links to .NET resources have been collated over time with the assistance of colleagues. ...
# May 7, 2006 2:49 AM
Anonymous comments are disabled
Page view tracker