Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why Wait for Asynchronous Web Services Calls

I was going through MSDN documentation on WebServices. Here and here, both these links talk about calling a webservice and wait for the response, which is also a general trend that I have seen while asynch implementation.

I don't understand "why do we need to wait for service call to return"? And, if we are waiting why don't make an synchronous call. What is the difference between an "asynch call followed by wait" and a "synchronous call"?

like image 272
noob.spt Avatar asked Dec 18 '25 00:12

noob.spt


2 Answers

To be useful, the asynchronous call needs to do its thing while you go do something else. There are two ways to do that:

  1. Provide a callback method for the asynchronous handle, so that it can notify you when it is completed, or

  2. Periodically check the asynchronous handle to see if its status has changed to "completed."

You wouldn't use a WaitHandle to do these two things. However, the WaitHandle class makes it possible for clients to make an asynchronous call and wait for:

  • a single XML Web service (WaitHandle.WaitOne),
  • the first of many XML Web services (WaitHandle.WaitAny), or
  • all of many XML Web services (WaitHandle.WaitAll)

to return results.

In other words, if you use WaitOne or WaitAny on an asynchronous web service that returns several results, you can obtain a single result from your web service call, and process it while you are waiting on the remaining results.

like image 162
Robert Harvey Avatar answered Dec 19 '25 13:12

Robert Harvey


One very practical use of asynchronous calls is stuff like this

http://i.msdn.microsoft.com/Bb760816.PB_oldStyle%28en-us,VS.85%29.png

If you want to update your UI while you're waiting for a 'server' to do something, you need to make an asynchronous call. If you make a synchronous call, your code will be stuck waiting, but if you make an asynchronous call you can update the UI or even let the user go do other stuff while you're waiting for the callback. This goes beyond UI, you may make an asynchronous call to start some non-critical task and continue on with your code and its possible you don't even register for a callback if the result is unimportant.

If you do NOTHING while waiting for the asyncronous call, then its less useful.

like image 39
TJB Avatar answered Dec 19 '25 12:12

TJB



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!