[英]Invoke WCF Method asynchronously
I have the following problem: 我有以下问题:
My WCF-Method looks like this 我的WCF方法看起来像这样
public TransferResult<bool> ExecuteMyMethod(string jobName,
Collection<KeyValuePair<string, string>> parameters)
{
do something;
}
The corresponding contract: 对应合同:
[OperationContract]
TransferResult<bool> ExecuteMyMethod(string jobName,
Collection<KeyValuePair<string, string>> parameters);
Now in our project there exists a proxy wrapper with which you can invoke methods asynchronously and which I must use: 现在,在我们的项目中,存在一个代理包装器,您可以使用它来异步调用方法,并且必须使用它:
public void InvokeAsync<TArg1, TArg2, TResult>(
Expression<Func<IMyServiceClient, Func<TArg1, TArg2, AsyncCallback, object, IAsyncResult>>> beginMethod,
Expression<Func<IMyServiceClient, Func<IAsyncResult, TransferResult<TResult>>>> endMethod,
TArg1 arg1,
TArg2 arg2,
Action<Task<TransferResult<TResult>>> continuationAction)
{
do something;
}
When I try to invoke my method like this: 当我尝试像这样调用我的方法时:
this.wrapper.InvokeAsync<string, Collection<KeyValuePair<string, string>>, bool>(
svc => svc.BeginExecuteMyMethod,
svc => svc.EndExecuteMyMethod,
"jobname",
parameters,
this.ContinuationAction);
The VS keeps telling me: VS一直告诉我:
Expected a method with 'IAsyncResult BeginExecuteMyMethod(string, Collection>, AsyncCallback, object)' signature 预期带有“ IAsyncResult BeginExecuteMyMethod(string,Collection>,AsyncCallback,object)”签名的方法
Can you please tell me what I'm doing wrong? 你能告诉我我做错了吗? The parameters parameter is of type Collection> I am very new to WCF and don't really know what the problem is :( parameters参数的类型为Collection>。我对WCF还是很陌生,实际上不知道问题出在哪里:(
Thanks in advance 提前致谢
Edit 编辑
I verified that the attribute [OperationContractAttribute(AsyncPattern=true)]
is set on the BeginExecuteMyMethod
method in the service reference 我验证了在服务参考中的BeginExecuteMyMethod
方法上设置了属性[OperationContractAttribute(AsyncPattern=true)]
Edit2 This is what the body of the IMyServiceClient looks like Edit2这是IMyServiceClient的主体的外观
[System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/IMyService/ExecuteMyMethod", ReplyAction="http://tempuri.org/IMyService/ExecuteMyMethod")]
TransferResult<bool> ExecuteMyMethod(string jobName, System.Collections.ObjectModel.Collection<MyService.KeyValuePairOfstringstring> parameters);
[System.ServiceModel.OperationContractAttribute(AsyncPattern=true, Action="http://tempuri.org/IMyService/ExecuteMyMethod", ReplyAction="http://tempuri.org/IMyService/ExecuteMyMethod")]
System.IAsyncResult BeginExecuteMyMethod(string jobName, System.Collections.ObjectModel.Collection<MyService.KeyValuePairOfstringstring> parameters, System.AsyncCallback callback, object asyncState);
TransferResult<bool> EndExecuteMyMethod(System.IAsyncResult result);
Look at the BeginExecuteMethod , parameters is type of Collection<KeyValuePairOfstringstring> , but if you look at your wrapper, you're calling InvokeAsync with different type Collection<KeyValuePair<string, string>> 查看BeginExecuteMethod ,参数是Collection <KeyValuePairOfstringstring>的类型,但是如果查看包装,您将调用具有不同类型Collection <KeyValuePair <string,string >>的 InvokeAsync。
BeginExecute method BeginExecute方法
IAsyncResult BeginExecuteMyMethod(string jobName, Collection<KeyValuePairOfstringstring> parameters, AsyncCallback callback, object asyncState);
InvokeAsync call InvokeAsync呼叫
this.wrapper.InvokeAsync<string, Collection<KeyValuePair<string, string>>, bool>(
svc => svc.BeginExecuteMyMethod,
svc => svc.EndExecuteMyMethod,
"jobname",
parameters,
this.ContinuationAction);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.