I have an asyncronous WCF service, that uses a client proxy to call an 2nd SOAP WCF service. I have no control of the SOAP Java service, but i can set the configuration on the service reference to run Asyncronously.
How would i get a result from the 2nd Async Service, to pass values back to the 1st down to the Client??
public class AddService : IAddService
{
// SOAP Java service reference
ResultServiceClient proxy = new ResultServiceClient();
public int AddNumbers(int x, int y)
{
// Am i on the right track here to use BeginXXX, EndXXX?
proxy.BeginGetResult(x, y, new AsyncCallback(OnEndAdd), null);
/// how to return a result here.??????
return result;
}
void OnEndAdd(IAsyncResult result)
{
int result = proxy.EndGetResult(result);
}
}
What’s going on here?
We make the call and then we use the ManualResetEvent to pause the thread and wait for the callback to be made. The ManualResetEvent is told to wait 10 seconds and then continue executing.
ManualResetEvent has multiple overloads for the Wait method, from infinite – Wait() – to the one I’m using, which takes a TimeSpan. _result is now a member variable so we can access the value from the initial calling method. I’ve also marked the service with a “PerCall” service behaviour. This means that a new instance of this object is instantiated per call to it. I do this because we’ve got an up-to 10 second delay while we call the Java service and we don’t want to block other calls to this service by other users.