如何从InvokeAsync捕获结果

时间:2017-07-17 22:44:58

标签: asynchronous

我正在尝试使用属于SIRI的WSDL进行异步调用(SIRI
实时信息的服务接口),如果我调用“GetStopMonitoringServiceAsync”,如何“捕获”响应?

WSDL的相关部分:

public void GetStopMonitoringServiceAsync(ServiceRequestStructure Request) {
        this.GetStopMonitoringServiceAsync(Request, null);
    }

    /// <remarks/>
    public void GetStopMonitoringServiceAsync(ServiceRequestStructure Request, object userState) {
        if ((this.GetStopMonitoringServiceOperationCompleted == null)) {
            this.GetStopMonitoringServiceOperationCompleted = new System.Threading.SendOrPostCallback(this.OnGetStopMonitoringServiceOperationCompleted);
        }
        this.InvokeAsync("GetStopMonitoringService", new object[] {
                    Request}, this.GetStopMonitoringServiceOperationCompleted, userState);
    }

    private void OnGetStopMonitoringServiceOperationCompleted(object arg) {
        if ((this.GetStopMonitoringServiceCompleted != null)) {
            System.Web.Services.Protocols.InvokeCompletedEventArgs invokeArgs = ((System.Web.Services.Protocols.InvokeCompletedEventArgs)(arg));
            this.GetStopMonitoringServiceCompleted(this, new GetStopMonitoringServiceCompletedEventArgs(invokeArgs.Results, invokeArgs.Error, invokeArgs.Cancelled, invokeArgs.UserState));
        }
    }

    /// <remarks/>
    public new void CancelAsync(object userState) {
        base.CancelAsync(userState);
    }

1 个答案:

答案 0 :(得分:0)

托管..

SS.GetStopMonitoringServiceCompleted += new GetStopMonitoringServiceCompletedEventHandler(GetStopMonitoringServiceCompletedEventHandler);


static void GetStopMonitoringServiceCompletedEventHandler(object sender, GetStopMonitoringServiceCompletedEventArgs e)
        {
            ServiceDeliveryStructure Response = new ServiceDeliveryStructure();
            Response = e.Result;
        }