Introduction:
If the Web service is invoked synchronously, the client application is blocked until the call returns.
We Can Create Async Methods using the client proxy.
Main:
1.Add ServiceReference
2.Check Generate asynchronous operations in the dialog Service Reference Settings.
3.For executing Web services asynchronously we need one delegate,normally it should
be async callback.
See the below examble,
localhost.Service1 ws=new localhost.Service1();
ws.Url=”http://” + servername + “service1.asmx”;
AsyncCallback ac=new AsyncCallback(this.UpdateRegions);
//creates an instance of the AsyncCallback delegate using a reference to the
procedure that should be called when the Web service response is received
ws.BeginGetRegions(ac,ws);
private void UpdateRegions(IAsyncResult ar){
localhost.Service1 ws=(localhost.Service1)ar.AsyncState;
string[] regions=ws.EndGetRegions(ar);
private void UpdateRegions(IAsyncResult ar){
localhost.Service1 ws=(localhost.Service1)ar.AsyncState;
string[] regions=ws.EndGetRegions(ar);
foreach(string reg in regions){
TreeNode n=new TreeNode(reg);
treeView1.Nodes.Add(n);
}
}
}
Conclusion:
Now,i hope you can understood how can we calling web services asynchronously,
Just we need to attach a delegate event handler for each thread.