【发布时间】:2014-05-04 01:42:55
【问题描述】:
我需要处理从 web 服务中检索到的多个数据,这些数据只获取我一个信息,如下例所示:
List<string> products = GetAllProducts();
List<ProductInfo> productsInfo = new List<ProductInfo>();
using (var channel = GetClientChannel<IService>("http://localhost:51383/Service/Service.svc"))
{
Parallel.ForEach(products, product =>
{
Request myRequest = new Request();
Response myResponse = null;
try
{
myRequest.ID = product;
myResponse = channel.GetProductInfo(myRequest);
productsInfo.Add(myResponse.Info);
}
catch (Exception ex)
{
// Continue build ProductInfo list
}
});
}
DoSomething(productsInfo);
这样的最佳方法是什么? 每个并行会提高性能还是不会因为我在同一个主机/端口中调用服务而受到影响?
【问题讨论】:
标签: c# web-services parallel-processing .net-3.5