Experience the elegance of. NET 2.0 (1)-asynchronous WebService call

Source: Internet
Author: User

In. net1.x, asynchronous WebService is generally called by calling the beginxx method corresponding to method XX. The process is similar to the use of asynchronous delegation. For more information, click here.

In. net2.0 (specifically VS 2005), an example of asynchronous WebService asynchronous call method is provided:

Void Dosomethingtest ()
{
Localhost. Service =   New Windowsapp. localhost. Service ();

Service. helloworldcompleted + =   New Windowsapp. localhost. helloworldcompletedeventhandler (service_helloworldcompleted );
// Do Asyn calling here
Service. helloworldasync ();
}

Void Service_helloworldcompleted ( Object Sender, windowsapp. localhost. helloworldcompletedeventargs E)
{
If (E. Error =   Null )
{
MessageBox. Show (E. Result );
}
Else
{
MessageBox. Show (E. Error. Message );
}
}

ServerCode


[WebService (namespace =   " Http://tempuri.org/ " )]
[Webservicebinding (conformsto = Wsiprofiles. basicprofile1_1)]
Public   Class Service: system. Web. Services. WebService
{
Public Service () {
}

[Webmethod]
Public   String Helloworld () {
Return "Hello World";
}
}

It's easy. No moreAsynccallback and iasyncresult are two annoying things. The called code becomes concise and elegant, and a strongly typed return value ("Hello World" in the preceding example) can be obtained from E. result "). However, if you are interested, you can check the referance. CS file generated by VS 2005, which is much more complicated than the referance. CS file generated by vs 2003. The system. componentmodel. asynccompletedeventargs and system. Threading. sendorpostcallback (delegate) are not found in. Net 1.x. It is estimated that more than the WebService client is used. Have time to study again.

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.