rusty
rusty

Reputation: 499

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. Originally the timeout on this httpwebrequest was set to 5 minutes.

Recently, the external service has been taking longer than 5 minutes to respond (which I am ok with). So I bumped the httpWebRequest.timeout up to 10 minutes.

Meanwhile the wcf service should be able to process other incoming requests (to functionB, functionC, etc). 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.

In the end everything completes properly, but I don't see why functionB is affected by the waiting that is happening over in 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.

Upvotes: 0

Views: 287

Answers (2)

Houssam Hamdan
Houssam Hamdan

Reputation: 908

You must decorate your WCF Service class with following attribute

[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.

"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."

Upvotes: 1

Mohammad
Mohammad

Reputation: 2764

i had a same problem. i hosted my service in IIS. after little search i found out its because of maxconnection limit in web config. i added this line in to my web.config and the problem solved:

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

by default maxconnection value is 2. but this is one of the many reasons. you should monitor your server requests in order to find out the exact reason.

Upvotes: 0

Related Questions