How to Limit Session Created in WCF Service

Throttling in WCF  provides some properties that we can use to limit how many instances or sessions are created at the application level. 

There are three settings in the config.

maxConcurrentCalls - Limits the total number of calls that can currently be in progress across all service instances. The default is 16.
maxConcurrentInstances - The number of InstanceContext objects that execute at one time across a ServiceHost. 
maxConcurrentSessions - A positive integer that limits the number of sessions a ServiceHost object can accept. The default is 10

We can manage these using Web.COnfig setting.

<system.serviceModel>

      <services >

 //Services Settings     

  </services>

      <behaviors>

          <serviceBehaviors>

              <behavior name="ServiceBehavior">

                  <serviceMetadata httpGetEnabled="true"/>

                  <serviceDebug includeExceptionDetailInFaults="true "/>

                  <serviceThrottling maxConcurrentCalls="500"  maxConcurrentInstances ="100" maxConcurrentSessions ="200"/>               

      </behavior>           

    </serviceBehaviors>       

  </behaviors>   

</system.serviceModel>

 

Ebook Download
View all
Learn
View all