Asynchronous Calls to Web Services
A normal synchronous call to a Web Service blocks the application till it receives the response from the Web Service. This is not a problem when the application is deployed in a private network with p
June 24, 2004
A normal synchronous call to a Web Service blocks the application till it receives the response from the Web Service. This is not a problem when the application is deployed in a private network with plenty of bandwidth. The problem could arise when the call is made over the Internet where the delay can be quite lengthy.
The solution is to call the Web Service asynchronously. Doing so enables us to call the web service on a separate thread, which allows us to continue our normal processing while the web service responds. There are a few ways to do the same. We will do so using Callbacks.
We have created a simple calculator web service, which has the following methods.
· Add
· Subtract
· Multiply
· Divide
The code for the same is given below.
<%@ WebService language="C#" class="Calculator" %> using System; using System.Web.Services; using System.Xml.Serialization; public class Calculator { [WebMethod] public int Add(int a, int b) { return a + b; } [WebMethod] public int Subtract(int a, int b) { return a - b; } [WebMethod] public int Multiply(int a, int b) { return a * b; } |