开发者

Is there any way to construct System.Web.Services.Protocols.InvokeCompletedEventArgs?

开发者 https://www.devze.com 2023-04-10 00:49 出处:网络
This is possibly a dumb question since I\'m new to all the technologies I\'m using here (C#, .NET and SOAP).There just may not be anyway to do what I want to do here.

This is possibly a dumb question since I'm new to all the technologies I'm using here (C#, .NET and SOAP). There just may not be anyway to do what I want to do here.

I've got an asynchronous SOAP call (code generated from WSDL) that I'm trying to alter in such a way that within my library, I'm actually making multiple calls to multiple different web servers and then aggregating the results to return back to the caller. The problem is that the SendOrPostCallback method of the asynchronous SOAP call expects to take an argument of InvokeCompletedEventArgs. I can't construct this because the constructor is declared internal. So while I can hide what I'm doing internally, and call the callback when what I'm doing is complete, I can't return the Results to the caller. Any suggestions?

Old Code:

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));
  }
}

New Code:

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[] { methodNam开发者_StackOverflow中文版e, 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);
}


Turns out it was a dumb question. The wsdl generation already subclasses that InvokeCompletedEventArgs. The class I suggested making in my comment above already exists in the generated code. I just needed to find it.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号