Pages

Wednesday, August 8, 2012

Asynchronous Web Services in .NET Using WSE 2.0


Introduction

When designing applications for consuming Web services, the response time needs to be taken into consideration. If the Web service happens to be on a remote server in an Internet scenario, the response times could be quite high due to heavy network traffic. Or, if the function call itself takes some time to return the response due to heavy processing involved, the response time would be high. A well-designed client application should not wait for the response for so long. It should manage its Web method calls efficiently, especially when there are multiple calls.
The ASP.NET Framework does provide support for accessing a Web service asynchronously. The user can wait until the request completes, can block on the WaitHandle, or wait for a callback function to be invoked. However, WSE 2.0 provides a potentially more powerful way of communicating with a Web service by using WS Addressing. In this white paper, you will see an approach to efficiently communicate with a Web service asynchronously.

WSE 2.0

WSE 2.0 is a .NET component that can be downloaded and installed into the .NET Framework. WSE is a Soap Extension that manipulates SOAP messages on both the client side and the server side if implemented in both. It provides a way to communicate by using industry standard SOAP messages, which in turn allows for interaction with Services implemented in other technologies. WSE v2.0 has some classes that allow standardized SOAP messages to be sent based on WS-Addressing, WS-Messaging, and the rest of WS-* specifications. This white paper discusses the SoapReceiver and SopaSender classes. The SoapReceiver class implements IHTTpHandler, which is a part of the Microsoft.Web.Services2.Messaging namespace.This class has a Receive method that passes the SOAP message as an input parameter whenever a HTTP Request or Response occurs. SoapSender is used to send messages by specifying the URI of the destination.

ASP.NET Web Services Using HTTPHandler

The HTTPHandler object is called by the HTTPApplication object whenever a request or response comes in or out of an ASP.NET Web page. The Handler is registered in the application configuration file. Once it is registered, every time a request comes for the specified ashx file, the code in the HTTPHandler is executed.
Here is a sample snippet of code for registering the HTTPHandler:
  1. <httpHandlers>
  2. <add type="AsyncWebClient.AsynReceiver,
  3. AsyncWebClient" path=" *.ashx" verb="*" />
  4. </httpHandlers>
The code in AsynReceiver class can be tuned to handle the request/response for the Web page.

Downloads

No comments:

Post a Comment