Bullines
Bullines

Reputation: 5696

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?

Upvotes: 6

Views: 1718

Answers (2)

Atanas Korchev
Atanas Korchev

Reputation: 30671

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

Upvotes: 1

craigmoliver
craigmoliver

Reputation: 6562

A Literal in a conditional Update Panel would be fine.

<asp:UpdatePanel ID="up" runat="server" UpdateMode="Conditional">
   <ContentTemplate>
     <asp:Literal ID="litUpdateMe" runat="server" />
   </ContentTemplate>
</asp:UpdatePanel>

Upvotes: 0

Related Questions