我正在使用WCF和TPL异步库,我需要的是能够请求多个WCF方法并等待所有步骤都完成,到目前为止,我发现.NET 4.5中有非常方便的方法Task.Factory.ContinueWhenAll可以用于等待所有通话结束
我发现了以下几种以异步方式请求WCF调用的方法
。通过使用由“添加引用”对话框生成的代理以及选项“生成基于任务的操作”-> [例如,此处] [1]-在我的情况下不是一个选项就像我们使用Raw ChannelFactory
Option 2一样。通过将同步调用包装在任务中,例如
ChannelFactory<IService1> factory = new ChannelFactory<IService1>("BasicHttpBinding_IService1");
Task<string> t1 = Task<string>.Factory.StartNew(() => { return factory.CreateChannel().GetData(2); });
Task<string> t2 = Task<string>.Factory.StartNew(() => { return factory.CreateChannel().GetData(5); });
Task.Factory.ContinueWhenAll(new[] { t1, t2 }, t =>
{
foreach (var task in t)
{
//get result here
}
});
Run Code Online (Sandbox Code Playgroud)
选项3.通过创建客户端异步版本的契约接口,例如
[ServiceContract(Namespace = "X", Name = "TheContract")]//Server side contract
public interface IService1
{
[OperationContract]
string GetData(int value);
}
[ServiceContract(Namespace = "X", Name = "TheContract")]//client side contract
public …Run Code Online (Sandbox Code Playgroud) 如何以编程方式确定此文件属于哪个分支?我花了3个小时试图弄明白没有结果.我找到了这个主题,但它不是我想要的:如何以编程方式获取有关TFS中分支的信息?