2

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.

John Saunders
  • 160,644
  • 26
  • 247
  • 397
Frank V
  • 25,141
  • 34
  • 106
  • 144
  • If you can't find a "max connections" property, then perhaps there is none. What do you want to do with it? Increase it? – John Saunders Jan 23 '14 at 19:48
  • I figured that is a possibility. First, I want to know the value to see if there is a potential bottleneck. I'm not making 100s of requests. I'm making like 3 at any give moment. And then if it's set to 1 or 2, I want to increase it a bit. We're having some performance concerns. – Frank V Jan 23 '14 at 19:49

2 Answers2

3

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

Haney
  • 32,775
  • 8
  • 59
  • 68
  • This has promise but I've not been able to get it fully working. Reason being is I have no way to pass the ServicePoint object in to my other relevant objects.... I'm still investigating though. – Frank V Jan 23 '14 at 21:31
  • You're right. I set it but I can not confirm if it's impactful to my situation since I'm not using the ServicePoint object.... Perhaps its used in the background but I don't know... – Frank V Jan 23 '14 at 23:04
  • @Haney thank you so much. Setting this has saved our team so much grief. – Isaac Baker May 11 '16 at 22:09
-2

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?

Community
  • 1
  • 1
landoncz
  • 1,997
  • 14
  • 15