有没有办法构造System.Web.Services.Protocols.InvokeCompletedEventArg

本文关键字:Web Services Protocols InvokeCompletedEventArg System 有没有 | 更新日期: 2023-09-27 18:10:22

这可能是一个愚蠢的问题,因为我对这里使用的所有技术(c#, . net和SOAP)都是新手。这里可能没有办法做我想做的事情。

我有一个异步SOAP调用(从WSDL生成的代码),我试图以这样一种方式改变,在我的库中,我实际上对多个不同的web服务器进行多次调用,然后聚合结果返回给调用者。问题是异步SOAP调用的SendOrPostCallback方法期望接受一个参数InvokeCompletedEventArgs。我不能构造这个,因为构造函数被声明为内部的。因此,虽然我可以在内部隐藏我正在做的事情,并在我正在做的事情完成时调用回调,但我不能将Results返回给调用者。有什么建议吗?

旧代码:

public void getStatusesAsync(RequestId[] requestIds, object userState)
{
  if ((this.getStatusesOperationCompleted == null))
  {
    this.getStatusesOperationCompleted = new System.Threading.SendOrPostCallback(this.OngetStatusesOperationCompleted);
  }
  this.InvokeAsync("getStatuses", new object[] {
                    requestIds}, this.getStatusesOperationCompleted, userState);
}
private void OngetStatusesOperationCompleted(object arg)
{
  if ((this.getStatusesCompleted != null))
  {
    System.Web.Services.Protocols.InvokeCompletedEventArgs invokeArgs = ((System.Web.Services.Protocols.InvokeCompletedEventArgs)(arg));
    this.getStatusesCompleted(this, new getStatusesCompletedEventArgs(invokeArgs.Results, invokeArgs.Error, invokeArgs.Cancelled, invokeArgs.UserState));
  }
}
新代码:

public void getStatusesAsync(RequestId[] requestIds, object userState)
{
  if ((this.getStatusesOperationCompleted == null))
  {
    this.getStatusesOperationCompleted = new System.Threading.SendOrPostCallback(this.OngetStatusesOperationCompleted);
  }
  asyncExecuteMultipleSoapCalls("getStatuses", new object[] { requestIds}, this.getStatusesOperationCompleted, userState);
}
private System.IAsyncResult asyncExecuteMultipleSoapCalls(string methodName, object[] args, System.Threading.SendOrPostCallback callback, object asyncState)
{
  Thread backgroundSoapCalls = new Thread(new ParameterizedThreadStart(asyncThreadRun));
  object[] threadArgs = new object[] { methodName, args, callback, asyncState };
  backgroundSoapCalls.Start(threadArgs);
  return null;//How to return AsyncResult?
}
private RequestStatus[] multiSoapCallResults = null;
private void asyncThreadRun(object args)
{
  string methodName = (string)(((object[])args)[0]);
  object[] methodArgs = (object[])(((object[])args)[1]);
  System.Threading.SendOrPostCallback methodCallback = (System.Threading.SendOrPostCallback)(((object[])args)[2]);
  object asyncState = (((object[])args)[3]);
  //To make a long story short, I'm using this thread to execute synchronous
  //SOAP calls, then call the event.  The reason is that different requestIds
  //in the passed in array may reside on different Web Servers.  Hopefully,
  //this will work similarly to the original Asynchronous call
  multiSoapCallResults = executeMultipleSoapCalls(methodName, methodArgs);
  //Now that I'm done, I want to pass the evenArgs to the SendOrPostCallback
  RequestStatus[] returnStatusArray = new RequestStatus[multiSoapCallResults.Length];
  multiSoapCallResults.CopyTo(returnStatusArray, 0);
  multiSoapCallResults = null;
  //This line doesn't compile of course, which is the problem
  System.Web.Services.Protocols.InvokeCompletedEventArgs eventArgs = new System.Web.Services.Protocols.InvokeCompletedEventArgs(null, false, null, returnStatusArray);
  //Need to pass event args here
  methodCallback(eventArgs);
}

有没有办法构造System.Web.Services.Protocols.InvokeCompletedEventArg

原来这是一个愚蠢的问题。wsdl生成已经包含了InvokeCompletedEventArgs的子类。我在上面的评论中建议的类已经存在于生成的代码中。我只是需要找到它