I am developing a webservice which is referencing a 3rd party API. When a method is invoked, results are obtained in the corresponding event handler. Users need to subscribe the event in order to obtain the results. Webservice exposes a method say Method1 (with [webmethod] attribute) which invokes API method. Result of API call is obtained in event handler created by webservice developer. Now any client consumes the webservice is able to call Method1. When client consumes the webservice enabling asynchoronous operations, .NET creates completed events for each method. In my case there will be "Method1Async" method and "Method1CompletedEvent". Completed event results return type of the method . How to return results obtained in event handler?
问问题
102 次
1 回答
1
尝试使用 ManualResetEvent
[WebMethod]
public object Method1()
{
object result = null;
var resetEvent = new ManualResetEvent(false);
var obj = new (3rd party object);
obj.(3rd party event) += (paras) =>
{
result = (3rd party result which in paras);
resetEvent.Set();
};
obj.method(...);
resetEvent.WaitOne();
return result;
}
于 2013-09-19T08:12:48.450 回答