Asynchronous WebService call

Source: Internet
Author: User

Asynchronous WebService call method and instanceCodeAs follows:

Main method (WebService call method ):

Arraylist al =   New Arraylist ();
Localhost. testservice TS =   New Testwebpro. localhost. testservice (); // This is the proxy class of WebService locally.
System. Threading. manualresetevent MRE =   New System. Threading. manualresetevent ( False );
Al. Add (TS );
Al. Add (MRE );

// Execute asynchronous call. localhost. testenum. Bus is a custom enumeration and is used as a parameter of the call method.
System. iasyncresult ar = TS. begintestmethod (localhost. testenum. Bus, New System. asynccallback ( This . Endcall), Al );

// . Execute other operations

Mre. waitone (); // Wait until the call is completed

// . Continue other operations


Callback method endcall (the method executed after the call is complete ):

Public   Void Endcall (system. iasyncresult AR)
{
  Try
  {
Arraylist al = (Arraylist) Ar. asyncstate;
Localhost. testservice TS = (Localhost. testservice) al [ 0 ];
System. Threading. manualresetevent MRE = (System. Threading. manualresetevent) al [ 1 ];

String S = TS. endtestmethod (AR ); // Obtain call results

Mre. Set (); // The notification master method can continue execution
}
  Catch (Exception ex)
  {
ThrowEx;
}
}

If the primary method and callback method are in the same class, TS and MRE can be declared as private global variables instead of being passed to the callback function through iasyncresult. asyncstate.

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.