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
Below code show, how to add the ‘ReleaseInstanceMode’ property to the operational behavior.
public interface ISimpleCalculator
int Add(int num1, int num2);
public int Add(int num1, int num2)
return num1 + num2;
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.
Reference books, you may like:Programming WCF Services: Design and Build Maintainable Service-Oriented Systems
WCF Multi-Layer Services Development with Entity Framework, 4th Edition
Learning WCF: A Hands-on Guide
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
You can also explicitly deactivate instance using InstanceContext object as shown below.
public interface IMyService
public class MyService:IMyService
public void MyMethod()
© 2015, admin. All rights reserved.