gpt4 book ai didi

c# - 有没有办法构造System.Web.Services.Protocols.InvokeCompletedEventArgs?

转载 作者:太空宇宙 更新时间:2023-11-03 14:11:45 24 4
gpt4 key购买 nike

这可能是一个愚蠢的问题,因为我对这里使用的所有技术(C#、.NET 和 SOAP)都是新手。反正这里可能没有我想做的事。

我有一个异步 SOAP 调用(从 WSDL 生成的代码),我试图以这种方式改变它,在我的库中,我实际上对多个不同的 Web 服务器进行多次调用,然后聚合结果返回给调用者。问题是异步 SOAP 调用的 SendOrPostCallback 方法期望采用 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);
}

最佳答案

事实证明这是一个愚蠢的问题。 wsdl 生成已经对 InvokeCompletedEventArgs 进行了子类化。我在上面的评论中建议创建的类已经存在于生成的代码中。我只是需要找到它。

关于c# - 有没有办法构造System.Web.Services.Protocols.InvokeCompletedEventArgs?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7616244/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com