Synchronous Versus Asynchronous Calls

As applications evolve, some components' method calls can take a long time to complete. This can occur when a method has to perform a complicated operation or search for a record or set of records from a database that has a large volume of records.

An example is a flight reservation system, where a search could be looking for a flight on day X from location A to location B and returning on a day Y from location B to location A. There are over 6000 flights per day in the United States alone. In addition, the search may have to access legacy systems to retrieve the possible flights that match the given criteria, and this can take some time.

When a synchronous call is made to a method, the client application is blocked until the method call has completed. In the case of the flight reservation system, once the user clicks the Search button, the client application would freeze and be released only when the method call is completed.

When an asynchronous call is made to a method, the client is not blocked and can, therefore, continue to perform additional processing tasks while the method is being executed. This fact allows the client application to present some kind of notice to the user that the request is being processed (a progress bar for example). When the method call has been completed, the information generated can then be used.

Asynchronous calls are made possible by decoupling the thread used to issue the method call from the thread that is used to perform the operation. This means that the client-side thread issues the call asynchronously and regains control immediately. On the server-side, the object acts as an asynchronous server and dispatches the method call to another thread, permitting the calling thread to be returned immediately.

Making calls to Web services is very similar to calls made to other components' methods. When a client makes a call to a Web Service method, the client will be “blocked” while waiting for the method execution to complete. As mentioned previously, this gives the end user the feeling that the application has frozen. To solve this problem, the Web Service method can be called asynchronously.

Fortunately for developers, the .NET Framework already does most of the plumbing, so this task is quite painless. As you will see in the following section, to perform an asynchronous call to a Web Service method, the developer of that Web Service does not have to write any additional code to handle asynchronous calls. Instead, the developer of the client application makes the decision to call a method synchronously or asynchronously.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.226.172.200