0

I have a .Net Proxy class that has several web service methods, each method has its Begin*Operation* and End*Operation*. I am experiencing web service requests that are getting stuck and has no response.

I am thinking of making use of the AsyncWaitHandle property of the return value of the Begin*Operation* method. I just dont know exactly where to put it.

Here is my code:

public activateResponse activateServiceReq([System.Xml.Serialization.XmlElementAttribute("activateServiceReq", Namespace = "http://AAA/BBB")] activateServiceReq activateServiceReq1)
{
    object[] results = this.Invoke("activateServiceReq", new object[] { activateServiceReq1});
    return ((activateServiceReqResponse)(results[0]));
}

//The Begin operation where I will use the AsyncWaitHandle.WaitOne

public System.IAsyncResult BeginactivateServiceReq(activateServiceReq activateServiceReq1, System.AsyncCallback callback, object asyncState)
{
    IAsyncResult result = this.BeginInvoke("activateServiceReq", new object[] { activateServiceReq1}, callback, asyncState);
    result.AsyncWaitHandle.WaitOne();
    return result;
}

/// <remarks/>
public activateServiceReqResponse EndactivateServiceReq(System.IAsyncResult asyncResult)
{
    object[] results = this.EndInvoke(asyncResult);
    return ((activateServiceReqResponse)(results[0]));
}
Suhaib Janjua
  • 3,538
  • 16
  • 59
  • 73
  • possible duplicate of [How to call wcf service Asynchronously](http://stackoverflow.com/questions/21481210/how-to-call-wcf-service-asynchronously) – noseratio Feb 12 '14 at 05:47
  • My example involves a plain web service and not a WCF one. I just want to ask for a suggestion or any efficient way to impose a wait before the asynchronous operation completes. – GabGomez Feb 12 '14 at 08:55
  • it's not clear, you have an XML web service proxy and you want to modify the generated code of it, i.e., `BeginactivateServiceReq` in this case? Where is the problem: calling the web service from the client side, or accepting calls on the server-side? – noseratio Feb 12 '14 at 09:09
  • Yes. The BeginactivateServiceReq and EndactivateServiceReq are auto generated methods using WSDL.exe. I want to use the WaitOne() method of BeginInvoke result so that any incoming thread will be blocked until the asynchronous operation completes. Is it possible? – GabGomez Feb 12 '14 at 09:17
  • This would be wrong. You should not modify the proxy code. Use the `Task.Factory.FromAsync` from [here](http://stackoverflow.com/questions/21481210/how-to-call-wcf-service-asynchronously) to call your proxy, it's not specific to WCF. Just substitute your own `BeginXXX`/`EndXXX` methods. – noseratio Feb 12 '14 at 09:20
  • But the web service calls come from an another application. I mean, the call directly invokes the web service method. – GabGomez Feb 12 '14 at 10:06
  • It's getting more confusing to me. Are you responsible for the web service code (server-side), or for the application code (client-side)? – noseratio Feb 12 '14 at 10:08
  • Im developing the client side where the actual web service call takes place. – GabGomez Feb 13 '14 at 08:39
  • *But the web service calls come from an another application* ... *Im developing the client side where the actual web service call takes place*... It's getting even more confusing now. Which application do you have the control over? – noseratio Feb 13 '14 at 08:45
  • There is a control system that sends the request (written using a proprietary language). The request is processes by a .Net Proxy where the request parameters are converted, then calls an actual web service. This is where I am involved. – GabGomez Feb 13 '14 at 09:39

0 Answers0