Review of Making Web Service Calls
page 12 of 17
by Wenfeng Gao
Average Rating: 
Views (Total / Last 10 Days): 78600/ 154
Article Contents:

Making Web Service Calls from ASPX Pages: Asynchronous PreRequestHandler Execution with Multiple Methods from Multiple Web Services

It is possible that you need to make multiple Web service calls from multiple Web services in order to load a page. Next I’ll shows you how to do that with the asynchronous PreRequestHandler execution approach. It is similar to do that with the asynchronous page approach.


Assume that I have two Web services: Service1 and Service2. Service1 has two methods: SlowMethod1 and FastMethod1. Service2 has two methods: SlowMethod2 and FastMethod2. To generate a page, I need to make calls to all the four methods. I’ll use the same four steps. I’ll highlight and mention those differences.


Step 1. Creating a class implementing IAsyncResult and a custom proxy class



Each proxy object will have a HashTable to store a bunch of IAsyncResult interfaces for calls on this proxy. Each key in the HashTable can also be used as the key for the result of the call stored in the request context.


Each MyAsyncResult object will have an ArrayList to store the references to the proxies. Each Global object will also have a count to track if all the calls are ready for harvest results. I increment the count each time when I make a Web service call and decrement the count each time when MyCallBack is invoked.


Step 2. Creating a BeginEventHandler method, an EndEventHandler method, and an intermediate MyCallback




Since the MyCallBack method calls might run on the different threads, multiple threads might access the count of my MyAsyncResult object. We use the lock statement to control access to the MyAsyncResult object proxy1.Res.


A unique MyAsyncResult object proxy1.Res is used in the BeginPreRequestHandlerExecute method because we make a bunch of asynchronous calls and the BeginPreRequestHandlerExecute method returns a single IAsyncResult interface. That is the reason why we wrap all the proxies in one MyAsyncResult object and each proxy object will have a HashTable to store a bunch of IAsyncResult interfaces for calls on this proxy.


When count equals to 0 in the MyCallback method, I harvest the response data for all the calls and make the Res.cb.Invoke call to relay the process.


Step 3. Calling the AddOnPreRequestHandlerExecuteAsync method


There is no change made.


Step 4. Using the response data


Using the response data is trivial.


View Entire Article

User Comments

Title: Code example   
Name: Sean Anderson
Date: 2009-05-26 8:02:17 AM
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
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
the article was a nice one.
it would be more good if sample code(downloadable) for asynchronous webservices.
can that be done?


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

©Copyright 1998-2024  |  Page Processed at 2024-04-15 3:04:41 AM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search