views:

682

answers:

2

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?

A: 

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>
craigmoliver
Would it make more sense to call MyWebSvc.DoWork() asynchronously from WebSvcsMgr.DoAllWork(), or rather call WebSvcsMgr.DoAllWork() asynchronously from the Web Form?
Bullines
Probably the web form if the user is not interacting with it or not user feedback is necessary.
craigmoliver
I mean the method, not the web form
craigmoliver
+1  A: 

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

korchev