简体   繁体   English

wcf服务长时间httpwebrequest等待导致后续请求排队

[英]wcf service long httpwebrequest wait causes queuing of subsequent requests

I have a WCF service that in functionA makes an HttpWebRequest call to functionX in an external service. 我有一个WCF服务,在functionA中对外部服务中的functionX进行HttpWebRequest调用。 Originally the timeout on this httpwebrequest was set to 5 minutes. 最初,此httpwebrequest的超时设置为5分钟。

Recently, the external service has been taking longer than 5 minutes to respond (which I am ok with). 最近,外部服务的响应时间已超过5分钟(我可以接受)。 So I bumped the httpWebRequest.timeout up to 10 minutes. 因此,我将httpWebRequest.timeout延长了10分钟。

Meanwhile the wcf service should be able to process other incoming requests (to functionB, functionC, etc). 同时,wcf服务应该能够处理其他传入请求(到functionB,functionC等)。 What I'm experiencing now is that if functionX takes longer than ~5 minutes to respond (and thus functionA takes longer than 5 minutes to complete), subsequent requests to functionB in my wcf service are queued / do not process until functionA completes. 我现在遇到的是,如果functionX花费的时间超过约5分钟(因此,functionA花费的时间超过5分钟才能完成),则对我的wcf服务中对functionB的后续请求将排入队列/在functionA完成之前不会处理。

In the end everything completes properly, but I don't see why functionB is affected by the waiting that is happening over in functionA. 最后,一切正常完成,但是我不明白为什么functionB受functionA中等待的影响。

Forgive me if that is hard to follow. 如果那很难遵循,请原谅我。 It is a strange and I'm having trouble wrapping my head around how these pieces are related. 这很奇怪,我很难理解这些部分之间的关​​系。

You must decorate your WCF Service class with following attribute 您必须使用以下属性装饰WCF服务类

[ServiceBehavior(ConcurrencyMode = ConcurrencyMode.Multiple)] // The service instance is multi-threaded.
public class Service1
{
   // ...
}

I assume your concurrency mode is set to Single defined as follows by Microsoft. 我假设Microsoft将您的并发模式设置为“单一定义”。

"The service instance is single-threaded and does not accept reentrant calls. If the System.ServiceModel.ServiceBehaviorAttribute.InstanceContextMode property is System.ServiceModel.InstanceContextMode.Single, and additional messages arrive while the instance services a call, these messages must wait until the service is available or until the messages time out." “服务实例是单线程的,并且不接受可重入的调用。如果System.ServiceModel.ServiceBehaviorAttribute.InstanceContextMode属性为System.ServiceModel.InstanceContextMode.Single,并且在实例为调用提供服务时出现其他消息,则这些消息必须等到服务可用,或者直到消息超时为止。”

i had a same problem. 我有一个同样的问题。 i hosted my service in IIS. 我将服务托管在IIS中。 after little search i found out its because of maxconnection limit in web config. 经过一点搜索后,我发现了它是因为Web配置中的maxconnection限制。 i added this line in to my web.config and the problem solved: 我将此行添加到我的web.config ,问题解决了:

<system.net>
    <connectionManagement>
        <add address="*" maxconnection="1000"/>
    </connectionManagement>
</system.net>

by default maxconnection value is 2. but this is one of the many reasons. 默认情况下,maxconnection值为2。但这是许多原因之一。 you should monitor your server requests in order to find out the exact reason. 您应该监视服务器请求,以查明确切原因。

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

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