Asynchronous Web Services in .NET Using WSE 2.0 | CodeGuru

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 […]

Written By
CodeGuru Staff
CodeGuru Staff
Oct 28, 2005
2 minute read
CodeGuru content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More

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.

Advertisement

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:

<httpHandlers>
  <add type="AsyncWebClient.AsynReceiver,
             AsyncWebClient" path=" *.ashx" verb="*" />
</httpHandlers>

The code in AsynReceiver class can be tuned to handle the request/response for the Web page.

CodeGuru Logo

CodeGuru covers topics related to Microsoft-related software development, mobile development, database management, and web application programming. In addition to tutorials and how-tos that teach programmers how to code in Microsoft-related languages and frameworks like C# and .Net, we also publish articles on software development tools, the latest in developer news, and advice for project managers. Cloud services such as Microsoft Azure and database options including SQL Server and MSSQL are also frequently covered.

Property of TechnologyAdvice. © 2026 TechnologyAdvice. All Rights Reserved

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.