Using Asynchronous Method Calls

As mentioned previously in this chapter, in the section on “Proxy Class Details,” web services allow the developer to call any of the exposed web methods either synchronously or asynchronously.

StockTickerConsumer in action

Figure 16-6. StockTickerConsumer in action

When a method is called synchronously, which is the “normal” way of doing method calls, the program execution waits for the method to return. As long as the method does not take too long to process and there is not too much network delay, this pause will not be a problem.

Figure 16-7 shows synchronous processing . Methods are called on the server via the proxy. The calling program is unaware a proxy is intervening in the process. A call goes out and when the results come back, the calling program continues processing.

Synchronous method calls

Figure 16-7. Synchronous method calls

However, in situations where the method is time-consuming to process (for example, a lengthy database operation or extensive computation) or where the network delay is significant, then this delay can be an unacceptable performance hit. In the case of web services, where all the method calls entail a round trip over the Internet, long network delays are common. Broadband Internet connections can help, but performance will still suffer.

One solution is to use asynchronous processing. ...

Get Programming ASP.NET, 3rd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.