21 March 2014

Instance Management



  

        Instance management refers to the way a service handles a request from a client. Instance management is set of techniques WCF uses to bind client request to service instance, governing which service instance handles which client request. It is necessary because application will differ in their need for scalability, performance, durability, transaction and queued calls.
       

         Basically there are three instance modes in WCF
        1. Per Call Instance Mode 
        1. Per Session Instance Mode 
        1. Singleton Instance Mode    


     

        Configuration:

       Instance mode can be configured using Service Behavior attribute. This can be specified at  implementing the service contract as shown below.

    [Service Contract()]
    public interface IMyService
    {
        [Operation Contract]
        int MyMethod();
    }   
    [Service Behavior(InstanceContextMode=InstanceContextMode.Single)]
    public class MyService:IMyService
    { 
        public int MyMethod()
        {
            //Do something
        }       
    }

No comments:

Post a Comment