Monday 28 December 2015

Can you limit how many instances or sessions are created at the application level?


Yes, you can limit how many instances or sessions are created at the application level. For this, you need to configure throttling behavior for the service in its configuration file. Some of these important properties are:



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






<behaviors>
 <serviceBehaviors>
   <behavior name="ServiceBehavior">
     <serviceThrottling maxConcurrentCalls="500" maxConcurrentInstances ="100" maxConcurrentSessions ="200"/>
   </behavior>





In this above post I explained you can limit how many instances or sessions are created at the application level

Can you control when the service instance is recycled?


Yes, we can control when the service instance is recycled using the ReleaseInstanceMode property of the OperationBehavior attribute. You can control the lifespan of your WCF service. You can set the value of ReleaseInstanceMode property as one of the following:

  • RealeaseInstanceMode.None: No recycling behavior.
  • RealeaseInstanceMode.BeforeCall: Recycle a service object before an operation is called.
  • RealeaseInstanceMode.AfterCall: Recycle a service object after an operation is called.
  • RealeaseInstanceMode.BeforeAndAfterCall: Recycle a service object both before and after an operation is called.


In this post I explained how to control when the service instance is recycled. I hope it is very helpful for you. Please comments your feedback and quries. Thank You.