ASP. NET Server multi-thread design -- asynchronous Web Service

Source: Internet
Author: User

After introducing asynchronous ihttphandler in the previous chapter, you should understand the benefits of asynchronous operations. It can release the threads in the server thread pool in time. When external operations are completed, the callback function is used to obtain data.

The following describes the asynchronous web service operations. In fact, they are similar to the asynchronous ihttphandler principle. Remember to use stream Asynchronization as an example in ihttphandler. The following uses sqlcommand as an example. (In other words, I am referring to the Asynchronous Method of the server, rather than the asynchronous call of the client)

[Iserializable]

Public class user {....}

Public class service1: system. Web. Service. webserivce

{

// The system automatically recognizes the beginmethod (parameter, asynccallback, object) and endmethod (iasyncresult) methods.

// And process it as an Asynchronous Method

[Webmethod]
Public iasyncresult begingetlist (INT age, asynccallback CB, object O)

{

Sqlconnection conn = new sqlconnection ("Data Source =...; asynchronous Processing = true ");

String commandstring = "select * from user as T1 where t1.age>" + age. tostring ();
Sqlcommand command = new sqlcommand (commandstring, Conn );
Conn. open ();
Return this. m_cmd.beginexecuteread (CB, command );

// At this time, the server thread will be released and callback will wake up when the command is complete

}

[Webmethod]
Public list <user> endgetlist (iasyncresult result)

{

Sqlcommand command = (sqlcommand) result. asyncstate;

Sqldataread READ = command. endexecuteread (result );

...... // Data Conversion

Return users;

}

}

When the client calls the getlist (INT age) method, the system can automatically identify the getlist (INT age) method because the information is easily transmitted through soap. You can also use the asynchronous call method on the client to call WebService, so that the system can work better together.

Unfortunately, Microsoft does not yet have a perfect asynchronous ADO. Net call mechanism. However, packaging SQL calls to asynchronous delegated calls does not help improve efficiency.

I suggest you tryUse Microsoft SQL Server Web Services toolkit to publish your database as a web service.

 

Summary:

ASP. NET webThe service provides an effective mechanism to asynchronously call backend services, so that valuable threads in the thread pool can be released in a timely manner. The server can use its ownWebMethod to maximize the number of simultaneously processed requests. You should consider using this method to develop high-performanceWebService ApplicationProgram.

 

ASP. NET Server multi-thread design-asynchronous Web Service

Multi-thread design on ASP. NET Server -- asynchronous ihttphandler

 

Related Article

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.