我有以下问题:
我的WCF-Method看起来像这样
public TransferResult<bool> ExecuteMyMethod(string jobName,
Collection<KeyValuePair<string, string>> parameters)
{
do something;
}
相应的合同:
[OperationContract]
TransferResult<bool> ExecuteMyMethod(string jobName,
Collection<KeyValuePair<string, string>> parameters);
现在在我们的项目中存在一个代理包装器,您可以使用它来异步调用方法,我必须使用它:
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;
}
当我尝试这样调用我的方法时:
this.wrapper.InvokeAsync<string, Collection<KeyValuePair<string, string>>, bool>(
svc => svc.BeginExecuteMyMethod,
svc => svc.EndExecuteMyMethod,
"jobname",
parameters,
this.ContinuationAction);
VS一直告诉我:
你能告诉我我做错了什么吗? 参数参数类型为Collection&gt; 我对WCF很新,并且不太了解问题所在:(预期使用&#39; IAsyncResult BeginExecuteMyMethod(字符串, Collection&gt;,AsyncCallback,object)&#39; 签名
提前致谢
修改
我验证了属性[OperationContractAttribute(AsyncPattern=true)]
是在服务参考中的BeginExecuteMyMethod
方法上设置的
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);
答案 0 :(得分:1)
查看 BeginExecuteMethod ,参数是集合&lt; KeyValuePairOfstringstring&gt; 的类型,但是如果你查看你的包装器,你将使用不同的类型调用InvokeAsync集合&lt; KeyValuePair&lt; string,string&gt;&gt;
BeginExecute方法
IAsyncResult BeginExecuteMyMethod(string jobName, Collection<KeyValuePairOfstringstring> parameters, AsyncCallback callback, object asyncState);
调用异步调用
this.wrapper.InvokeAsync<string, Collection<KeyValuePair<string, string>>, bool>(
svc => svc.BeginExecuteMyMethod,
svc => svc.EndExecuteMyMethod,
"jobname",
parameters,
this.ContinuationAction);