December 12, 2006

WCF : Instance Context object

The WCF runtime creates an Instance Context object to control the interaction between the channel stack and the service instance.

Instance Context Mode Values

InstanceContextMode.PerCall
A new instance of the service will be created every time a client calls an operation. When the call completes, the service instance is recycled.

InstanceContextMode.PerSession

If the service implements sessions, a new instance of the service will be created at the start of the session and recycled when the session completes. A client can call the service several times during a session. However, the service instance cannot be used across more than one session.

InstanceContextMode.Single Only one instance of the service is created and is shared by all clients and all sessions. The instance is created when the first client attempts to access it.

You can specify the InstanceContextMode property for a service like this:

[ServiceBehavior (InstanceContextMode=InstanceContextMode. PerSession) ]
public class ProductsServiceImpl : IProductsService{
}