Server-side asynchronous Web method (I)

Source: Internet
Author: User
Abstract: Matt Powell describes how to use asynchronous Web methods on the server to create a high-performance Microsoft ASP. NET Web service.
Introduction
In the third column in May September (English), I talked about the problem of using the client function of Microsoft & reg;. NET Framework to call Web services asynchronously over HTTP. This method is very useful for calling Web services, so you do not have to lock your application or generate too many background threads during use. Now let's take a look at the asynchronous Web method that provides similar functions on the server side. The asynchronous Web method has a high performance similar to the HSE_STATUS_PENDING method in writing ISAPI extensions. However, you do not need to write code for managing your own thread pool, and it also has all the advantages of running managed code.
First, let's consider the general Microsoft & reg; ASP. NET Web synchronization method. When you return a result from a synchronous Web method, a response is sent to the method. If it takes a long time to complete the request, the request processing thread will be occupied until the method call ends. Unfortunately, most long calls are caused by long database queries or calls to another Web service. For example, if you call the database, the current thread will wait until the call is completed. The thread has nothing to do, but waits until the query is returned. When the thread waits for the completion of the call to the TCP socket or backend Web service, a similar problem occurs.
It is not good to keep the thread in the waiting state, especially when the server is under heavy pressure. The waiting thread does not perform any valid work, such as providing services for other requests. We need to find a way to start a long background process on the server and return the current thread to the ASP. NET process pool. Then, when a long background process is completed, we call a callback function to end processing the request and notify ASP. NET that the request has been completed in some way. In fact, this function can be provided by ASP. NET using asynchronous Web methods.
Working Principle of asynchronous Web method
When you write a typical ASP.. NET Web service, Microsoft & reg; Visual Studio & reg ;. net only compiles your code to create an assembly. When you receive a request for its Web method, the assembly is called. The Assembly itself does not know anything about SOAP. Therefore, when your application is started for the first time, the ASMX handler must reflect your Assembly to determine which Web methods are provided. For conventional synchronous requests, these operations are simple: find out which methods have the associated WebMethod attributes, and set the logic to call the correct method based on the SOAPAction HTTP header.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.