Max Outbound connections

4.7k views Asked by At

I have an application written in c# on .NET 4.0 which needs to make multiple web service requests. The web service requests vary in nature but are mostly requesting information.

The Types involved is a derivative of System.ServiceModel.ClientBase

The connection is setup in code and uses types such as BasicHttpBinding, EndpointAddress, and CustomBinding to name a few.

How can I determine the max number of concurrent requests that can be made on the derivative of the ClientBase?

I've not been able to find any property that pertains to MaxConnections but I do come across things like NetTcpBinding.MaxConnections and ConnectionManagementElement.MaxConnection but neither of these seem compatible with my leveraged APIs. Either I'm missing how to use them, this isn't available or I don't know where to look.

2

There are 2 answers

3
Haney On BEST ANSWER

WCF is an abstraction on core networking concepts. For HTTP bindings, it falls under the ServicePoint configuration which determines things like your HTTP concurrent connection limits.

You want ServicePointManager.DefaultConnectionLimit for HTTP:

http://msdn.microsoft.com/en-us/library/system.net.servicepointmanager.defaultconnectionlimit.aspx

You can also do this via your config file:

http://msdn.microsoft.com/en-us/library/fb6y0fyc.aspx

4
landoncz On

This would be in the binding configuration section of the service host's .config file. Depending on the binding being used, you can set things like maxConcurrentCalls and maxConcurrentSessions, there are usually default limits for them imposed by WCF.

Real life example:

<system.serviceModel>
        <behaviors>
            <serviceBehaviors>
                <behavior name="ServiceBehaviorBasicHttp">
          <serviceThrottling maxConcurrentCalls="1000" maxConcurrentSessions="1000" maxConcurrentInstances="1000"/>
                    <serviceMetadata />
                </behavior>
</system.serviceModel>

Or in code behind, something like this:

ServiceHost host = new ServiceHost(typeof(MyService));
ServiceThrottlingBehavior throttleBehavior = new ServiceThrottlingBehavior
{
    MaxConcurrentCalls = 40,
    MaxConcurrentInstances = 20,
    MaxConcurrentSessions = 20,
};
host.Description.Behaviors.Add(throttleBehavior);
host.Open();

Taken from here: WCF: How do I add a ServiceThrottlingBehavior to a WCF Service?