简体   繁体   English

WCF Web服务调用多个Web服务异步

[英]WCF Web services calling multiple web services asynchronous

I am facing an issue from one WCF Web Service that I have created. 我面临着我创建的一个WCF Web服务的问题。 This web service calls multiple web services to be able to build up its response for the caller. 该Web服务调用多个Web服务,以便能够为调用者建立响应。

var carInformation = Task.Run(() => carProvider.GetCarByCarNumberAsync(brandCode, carNumber));
var carHistory = Task.Run(() => carProvider.GetCarHistoryByCarNumberAsync(brandCode, carNumber));
var carConf = Task.Run(() => carProvider.GetConfByCarNumberAsync(brandCode, carNumber));
var carAdvSet = Task.Run(() => carProvider.GetAdvSetyByCarNumberAsync(brandCode, carNumber));
var carComp = Task.Run(() => carProvider.GetComponentsyByCarNumberAsync(brandCode, carNumber));
var carDealersComments = Task.Run(() => carProvider.GetDealerCommentsByCarNumberAsync(brandCode, carNumber));
var carPromotions = Task.Run(() => carProvider.GetCarPromotionsAsync(brandCode, carNumber));
var carCompetitors = Task.Run(() => carProvider.GetCompetitorsAsync(brandCode, carNumber));
var carSuppliers = Task.Run(() => carProvider.GetSupplierssAsync(brandCode, carNumber));

List<Task> taskList = new List<Task>();
taskList.Add(carInformation);
taskList.Add(carHistory);
taskList.Add(carAdvSet);
taskList.Add(carComp);
taskList.Add(carDealersComments);
taskList.Add(carPromotions);
taskList.Add(carCompetitors);
taskList.Add(carSuppliers);

await Task.WhenAll(taskList);

According to the above code snippet, I am expecting that all calls will get executed at the same time, since these are not dependent on each other. 根据上面的代码片段,我期望所有调用都将在同一时间执行,因为它们彼此不依赖。 But this is not happening, when I look into the IIS Logs (from the other web service) or even if I user Fiddler to log all this requestes, I see only 5 are executed at the same time and the other ones are getting executed between the first are waiting for a response or in other cases are after one of those async calls had finalized. 但这并没有发生,当我查看IIS日志(来自其他Web服务)时,或者即使我使用Fiddler记录了所有这些请求,我也看到同一时间仅执行了5个请求,而其他请求却在两个之间执行了。第一个在等待响应,或者在其他情况下是在其中一个异步调用完成之后。

Am I missing some configuration on the IIS that my web service is hosted? 我是否在托管Web服务的IIS上缺少某些配置? Or a setting in web config that allows more thread creation on PerCall. 或Web配置中的一项设置,允许在PerCall上创建更多线程。

WCF服务类上的[ServiceBehavior(UseSynchronizationContext = false)]属性将有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM