Asyncronous Web Service

J

jeff

I need to turn an asyncronous call into a syncronous one.

I have a Web Applicaition which makes a call to web services to
retrieve data.

A new web service that I need to support work asyncronously...sort
of. The way it is set up is I make a call into a third party web
service, and get a job reference returned. About 5 seconds later the
third party calls into a web service which I provide with a response.

I want my application to call the web service and then go to sleep.
When my web service is called my thread can return the my web app.

Does anyone know how this can be done?

THanks
 
V

Valko

In .NET Framework version 2.0 Web service proxy automatically creates for you
and includes a method named YourMethodNameAsync and an event named
YourMethodNameCompleted.

You can call YourMethodName asynchronously by registering a handler for
YourMethodNameCompleted events and calling YourMethodNameAsync, like this:



YourWebSvcProxy.YourMethodNameCompleted += new
YourMethodNameCompletedEventHandler (OnYourMethodNameCompleted);
YourWebSvcProxy.YourMethodNameAsync (YourObject);
....
void OnYourMethodNameCompleted (Object source,
YourMethodNameCompletedEventArgs e)
{
// This bit is Called after YourMethodName completes
}

So you call asynchronously your YourMethodNameAsync then after it finishes
whatever it do, it returns the call back to OnYourMethodNameCompleted.

Basically the same concepts apply to .NET 1.1 - you should create your own
asyncCall delegate and explicitly to start asynchronous call with
BeginYourMethodName and EndYourMethodName like this:

// Create a delegate to handle the callback
AsyncCallback asyncCall =
new AsyncCallback(OnYourMethodNameCompleted);

YourWebSvcProxy.BeginYourMethodName(YourObject, asyncCall, null);


private void OnYourMethodNameCompleted(IAsyncResult asyncResult)
{

// Get the Result of the WebMethod by calling
// the end method of the proxy class
YourObject YourResult = YourWebSvcProxy.EndYourMethodName(asyncResult);

}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,143
Latest member
SterlingLa
Top