WCF Instance Deactivation – Easy WCF
Skip to content

WCF Instance Deactivation

WCF Instance Deactivation:

service instance is hosted in a context. Session correlates the client message not to the instance, but to the context that host it. When session starts, context is created and when it closes, context is terminated.

WCF provides the option of separating the two lifetimes and deactivating the instance separately from its context.

ReleaseInstanceMode property of the OperationalBehavior attribute used to control the instance in relation to the method call.

Below are the list Release mode available in the ReleaseInstanceMode

  1. RealeaseInstanceMode.None
  2. RealeaseInstanceMode.BeforeCall
  3. RealeaseInstanceMode.AfterCall
  4. RealeaseInstanceMode.BeforeAndAfterCall

Below code show, how to add the ‘ReleaseInstanceMode’ property to the operational behavior.


This property means that it will not affect the instance lifetime. By default ReleaseInstanceMode property is set to ‘None‘.


This property means that it will create new instance before a call is made to the operation.

If the instance is already exist,WCF deactivates the instance and calls Dispose() before the call is done. This is designed to optimize a method such as Create()


This property means that it will deactivate the instance after call is made to the method.

This is designed to optimize a method.


This is means that it will create new instance of object before a call and deactivates the instance after call. This has combined effect of using ReleaseInstanceMode.BeforeCall and ReleaseInstanceMode.AfterCall

Explicit Deactivation

You can also explicitly deactivate instance using InstanceContext object as shown below.

© 2015, admin. All rights reserved.

Leave a Reply

Your email address will not be published. Required fields are marked *