Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Updating UI After Asynchronous WebMethod Calls

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?

like image 333
Bullines Avatar asked Sep 30 '08 15:09

Bullines


1 Answers

Asynchronous pages are helpful in scenarios when you need to asynchronously call web service methods.

like image 99
Atanas Korchev Avatar answered Oct 05 '22 00:10

Atanas Korchev