O'Reilly logo

Programming ASP.NET, 3rd Edition by Dan Hurwitz, Jesse Liberty

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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. ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required