Instance management in WCF

Posted By : Bipul Kumar Tiwari,

Instance management is the technique where WCF client make a requests to a WCF object and WCF service instance serves the request and sends the response to the WCF client.

There are three possible ways by which you can control WCF service instances:

Pre call , Pre session and Single instances

Per call instance mode:



In simple word , for every WCF client method call, a WCF service instance is created, and destroyed once the request is served. Every time the client sends a new request either from the same proxy or a different proxy, a new service instance is always created.

[ServiceBehavior(InstanceContextMode = InstanceContextMode.Percall)]
public class Service : IService
{
// Your method
}


When we use PerCall :

Per session instance mode:


The PerSession instance mode specifies that one instance of WCF service class will be created for each client.
In simple word One instance of the service class is created per client session. Each proxy will connect to new instance means if one client have two proxy then two server instance will created.

[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerSession)]
public class Service : IService
{
// Your function
}

When we use PerSession :

Single instance mode:


Single services instance for all client connection and activation. Mince it doesn't matter whether the requests coming form different endpoint or different proxy.
[ServiceBehavior(InstanceContextMode = InstanceContextMode.Single)]
public class Service : IService
{
// Your function
}

Related Articles

 

About the Author

author
Its me BIPUL who is logically minded creative at heart , a good communicator , a self taught full stack developer. I constantly focuses on my thinking , reading , collecting and creating my work in a order to enhance my skills.

I discover new dimensions for growing bussiness with a proven record in creating database and programming. I have a strong technical skills as well as strong interpersonal skills. Read more...
 

Browse By Category

Popular Articles