Windows Azure: Avoiding WCF Service Throttling by increasing maximum concurrent connection count in WCF service Configuration

Recently I was working on a WCF based Application running in Windows Azure however this WCF service was not able to connect more than 100 concurrent connections. We could consistently observed that when the service hits the limit of exactly 100 connections, then new clients cannot connect to the service endpoint.

After some investigation, I could find the following details about this issue and how to solve it.

The WCF service running in Windows Azure was being throttled by hitting maximum concurrent connections, that’s why when total number of concurrent connection hits the threshold value (in this case 100), service was not able to serve further connection to any client.

To solve this problem we needed to increase the concurrent connections in the service configuration. There are two ways to configure the service configuration:

(For example we are modifying the maximum concurrent connection from 100 to 200)

Option #1 Change Service Throttling (serviceThrottling) setting in web.config/app.config as below: 

 <configuration>
 ... 
 <system.serviceModel>
 <services>
 <service name="YourServiceName" behaviorConfiguration="Throttled">
 <endpoint address="" binding="wsHttpBinding" contract="ISampleService">
 <identity>
 <dns value="localhost"/> 
 </identity>
 </endpoint>
 <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/> 
 </service>
 </services>
 <behaviors>
 <serviceBehaviors>
 <behavior name="Throttled">
 <serviceMetadata httpGetEnabled="true"/> 
 <serviceDebug includeExceptionDetailInFaults="false"/> 
 <serviceThrottling maxConcurrentCalls="200" maxConcurrentSessions="200" /> 
 </behavior>
 </serviceBehaviors>
 </behaviors>
 </system.serviceModel>
 </configuration>
 

 

Option #2: You can also change service throttling (serviceThrottling) directly in your Service Code by setting ServiceThrottlingBehavior properties to change the concurrent calls number as below:

 

  // configure the service endpoint
 host.AddServiceEndpoint(typeof(IServerWithCallback), binding, endpointurl, new Uri(listenurl));
 
 // bump up the number of sessions supported by adding throttle behaviour
 ServiceThrottlingBehavior throttle = host.Description.Behaviors.Find<ServiceThrottlingBehavior>();
 if (throttle == null)
 {
 throttle = new ServiceThrottlingBehavior();
 
 throttle.MaxConcurrentCalls = 10;
 throttle.MaxConcurrentInstances = 200;
 throttle.MaxConcurrentSessions = 200;
 
 host.Description.Behaviors.Add(throttle);
 }
 
 // start the service endpoint
 host.Open();
 

That's it.