Thursday, June 7, 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.

                             In wcf this refers to how wcf creates instances for serving the requests.Wcf provides almost all instance patterns for building effective wcf service.

Modes Of Service Instances :

  • Per-Call instance mode
  • Per-Session instance mode
  • Singleton Instance Mode

1. Per-Call instance mode:  

 A new service instance is created and destroyed for every call.

  • When we configure a WCF service as per call, new service instances are created for every method call you make via a WCF proxy client.
  • The WCF client makes the first method call (method call 1).
  • A new WCF service instance is created on the server for this method call.
  • The WCF service serves the request and sends the response and the WCF instance is destroyed and given to the garbage collector for clean up.
  • Now let’s say the WCF client makes a second method call, a new instance is created, the request is served, and the WCF instance is destroyed.
  • In other words, for every WCF client method call, a WCF service instance is created, and destroyed once the request is served.

Per-Call
                                                             Per-Call Service


2.Per-Session instance mode :

One Service instance per clients.Clients can't share instance with other clients.
  • The client creates the proxy of the WCF service and makes method calls.
  • A WCF service instance is created which serves the method response.
  • The client makes one more method call in the same session.
  • The same WCF service instance serves the method call.
  • When the client finishes its activity, the WCF instance is destroyed and served to the garbage collector for clean up.
Per-Session
Per-session Service

3. Singleton Instance Mode:

All clients share same service instance and use InstanceContextMode of ServiceBehavior attribute to indicate it.

  • WCF client 1 requests a method call on the WCF service.
  • A WCF service instance is created and the request is served. The WCF service instance is not destroyed, the service instance is persisted to server other requests.
  • Now let’s say some other WCF client, e.g., client 2, requests a method call.
  • The same WCF instance which was created by WCF client 1 is used to serve the request for WCF client 2. In other words, only one global WCF server service instance is created to serve all client requests.
Singleton Service

Singleton Service



No comments:

Post a Comment