Возможно, это глупый вопрос, так как я новичок во всех технологиях, которые я здесь использую (C #, .NET и SOAP). Просто не может быть в любом случае делать то, что я хочу сделать здесь.
У меня есть асинхронный вызов SOAP (код, сгенерированный из WSDL), который я пытаюсь изменить таким образом, чтобы в моей библиотеке я фактически делал несколько вызовов на несколько различных веб-серверов, а затем собирал результаты вернуться обратно к звонящему. Проблема заключается в том, что метод SendOrPostCallback асинхронного вызова SOAP предполагает получение аргумента InvokeCompletedEventArgs. Я не могу построить это, потому что конструктор объявлен внутренним. Поэтому, хотя я могу скрыть, что я делаю внутри, и вызвать обратный вызов, когда то, что я делаю, завершено, я не могу вернуть результаты вызывающей стороне. Есть предложения?
Старый код:
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);
}