Saturday 28 January 2012

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:
  • Per-Call instance mode
  • Per-Session instance mode
  • Singleton Instance Mode


Configuration:

Instance mode can be configured using ServiceBehavior attribute. This can be specified at implementing the service contract as shown below.
 [ServiceContract()]
    public interface IMyService
    {
        [OperationContract]
        int MyMethod();
    }

   
    [ServiceBehavior(InstanceContextMode=InstanceContextMode.Single)]
    public class MyService:IMyService
    {

        public int MyMethod()
        {
            //Do something
        }       
    }

No comments:

Post a Comment