views:

151

answers:

1

Hi, I am calling a ASP.NET webservice which is marked as one-way. I wrapped the code that calls the web service in a try catch block, but it is not catching the exceptions thrown by the web service. when I test the webservice separately by entering the url in the browser, it throws an error, but the exception is not sent to the calling code for some reason. here is the sample code

/// <summary>
/// Summary description for WebService
/// </summary>
[WebService(Namespace = "http://mycompany.com/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[ToolboxItem(false)]
public class TestWebService : System.Web.Services.WebService
{
    [SoapDocumentMethod(OneWay = true)]
    [WebMethod(Description="Start a long running process.")]
    public void LongRunningProcess()
    {
        //do some long process
    }
}

//calls proxy class method
TestWebService testWebService = new TestWebService();
testWebService.Timeout = Timeout.Infinite;
testWebService.Credentials = CredentialCache.DefaultCredentials;
testWebService.Url = <url> //the web service url
testWebService.LongRunningProcess()

any help would be appreciated.

+2  A: 

I don't believe you can.

The whole point of stating a method is one way is to mark it as a fire-and-forget, the client does not have to wait for the method to be invoked.

As soon as the server parsed the request, and often before it actually invokes the method, it returns http 202, at which point the client moves on.

Yossi Dahan
Correct. By definition, a OneWay method is unable to report anything back to the caller regarding the success or failure of the call.
GalacticCowboy
I think this is a limitation with one way webservice call. instead it may be better to call it asynchronously and implement a callback method to catch any exceptions unless there is a better way to execute a long running process from the web interface when user clicks a button. I thought about running the process on a separate thread, but not sure what happens if the user closes the browser mid-way. so what I did was to store user input in database and invoke a web service in the background through a scheduler to execute it. the process takes around 15 mins to complete.usercan checkstatuslater
RKP