Greetings!
I have a WebService that contains a WebMethod that does some work and returns a boolean value. The work that it does may or may not take some time, so I'd like to call it asynchronously.
[WebService(Namespace = "http://tempuri.com/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
public class MyWebSvc : System.Web.Services.WebService
{
[WebMethod]
public bool DoWork()
{
bool succ = false;
try
{
// do some work, which might take a while
}
catch (Exception ex)
{
// handle
succ = false;
}
return succ;
}
}
This WebService exists on each server in a web farm. So to call the DoWork() method on each server, I have a class library to do so, based on a list of server URLs:
static public class WebSvcsMgr
{
static public void DoAllWork(ICollection<string> servers)
{
MyWebSvc myWebSvc = new MyWebSvc();
foreach (string svr_url in servers)
{
myWebSvc.Url = svr_url;
myWebSvc.DoWork();
}
}
}
Finally, this is called from the Web interface in an asp:Button click event like so:
WebSvcsMgr.DoAllWork(server_list);
For the static DoAllWork() method called by the Web Form, I plan to make this an asynchronous call via IAsyncResult. However, I'd like to report a success/fail of the DoWork() WebMethod for each server in the farm as the results are returned. What would be the best approach to this in conjuction with an UpdatePanel? A GridView? Labels? And how could this be returned by the static helper class to the Web Form?
Asynchronous pages are helpful in scenarios when you need to asynchronously call web service methods.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With