Review of Making Web Service Calls
page 15 of 17
by Wenfeng Gao
Feedback
Average Rating: 
Views (Total / Last 10 Days): 80404/ 223
Article Contents:

Making Web Service Calls from Web Services: Implementing an Asynchronous Web Method

Implementing an asynchronous XML Web service method follows the .NET Framework asynchronous design pattern.

 

So if we had a Web method whose synchronous declaration looked like this:

 

 

Then an asynchronous declaration would look like this:

 

 

We split the synchronous method into two methods; each with the same base name - one with that name starting with Begin and the other End. The BeginLengthyProcedure function returns an IAsyncResult interface and takes as its last two input parameters an AsyncCallback, and an object respectively. The EndLengthyProcedure function takes as its only parameter an IAsyncResult interface. Both must be flagged with the WebMethod attribute. In the BeginLengthyProcedure function, I made an asynchronous Web service call. The call takes the same cb, a parameter for BeginLengthyProcedure, as its parameter. This will cause that the EndLengthyProcedure function is invoked when the DelayedResponse call completes. The EndLengthyProcedure function will harvest the result of the DelayedResponse call and return it.

 

The following code example demonstrates how to chain asynchronous calls when a Web service method makes more than one asynchronous call and the calls must execute sequentially.

 

 

We have Web services: Service1 with a Web method DelayedResponse and Service 2 with a Web method DelayedResponse2. The BeginLengthyProcedure method makes an asynchronous call to Service 1 and sets up an intermediate callback named ChainCallback to receive the results. That intermediate callback then asynchronously calls to Service 2 and The EndLengthyProcedure function will harvest the result of the DelayedResponse2 call and return it.

 


View Entire Article

User Comments

Title: Code example   
Name: Sean Anderson
Date: 2009-05-26 8:02:17 AM
Comment:
Likewise, I would be very interested in seeing a working example of this, as I have read the article here (and the one on MSDN) both of which give a very good overview of the approach, but without a full example I am rapidly getting stuck.
Title: Great articles but...   
Name: Pascal
Date: 2009-05-21 7:38:29 AM
Comment:
Same comments, great articles but would be nice to have a sample code, not that easy to try when you don't know where you going.
Title: req sample code downloadable..   
Name: Karthik
Date: 2006-01-02 1:13:44 AM
Comment:
Hi,
the article was a nice one.
it would be more good if sample code(downloadable) for asynchronous webservices.
can that be done?

Regards,
Karthik






Community Advice: ASP | SQL | XML | Regular Expressions | Windows


©Copyright 1998-2019 ASPAlliance.com  |  Page Processed at 2019-09-17 10:52:56 AM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search