Tuesday, May 5, 2015

Three modes of WCF Instance management

WCF instance management Interview Question

An idea  to write this blog to get familiar with 3 modes of WCF instance management , how all does work in context to WCF.

 

image

Three modes are given below:


  1. InstanceContextMode. PerCall
  2. InstanceContextMode. PerSession
  3. InstanceContextMode. Single

These all are describe in a detail below:

InstanceContextMode. PerCall

It means each client request call will be served by the new WCF Service instance.e.g. Each time when client makes a method call ,A new service instance is created on the server to serve the request.After responding to server it gets destroyed and managed by Garbage collection.This is the routine process on each client request to server.

   1:  [ServiceBehavior(InstanceContextMode = InstanceContextMode.Percall)] 
   2:  public class Service : IService
   3:  {
   4:  }
InstanceContextMode. PerSession: 
It means each client will have a separate WCF Service instance to serve the WCF client request.It maintains the client state.The client makes one method call in the same session and the same WCF service instance serves the another method call. Which is different from the PerCall.
After the client finishes its activity, the WCF instance is destroyed  and managed by the garbage collector for clean up.

You can decorate Service with this annotation.


   1:  [ServiceBehavior(InstanceContextMode = InstanceContextMode.Percall)] 
   2:  public class Service : IService
   3:  {
   4:  }



InstanceContextMode. Single :


It means All client request is maintained and served by the single WCF Service instance.In this case WCF service instance doesn't get destroyed, the service instance persists on to server to handle other requests.One global WCF server service instance is created to serve all client requests.


   1:  [ServiceBehavior(InstanceContextMode = InstanceContextMode.Single)] 
   2:  public class Service : IService
   3:  {
   4:  }
These may be helpful down the line .Enjoy Coding and Smile Smile

0 comments :

Post a Comment