Do you know when to use the different WCF Context Modes?


Let's talk about WCF's InstanceContextMode, give a brief overview of the possible values and determine when to use them.

InstanceContextMode is a property on the ServiceBehaviorAttribute class in .NET Framework 4.5. A developer will use the InstanceContextMode property to specify when new service objects are created.

Because the service object is not directly connected to the communicating channel, the lifetime of the service objects is independent of the lifetime of the channel between a client and the service application. The default value, PerSession, instructs the service application to create a new service object when a new communication session is established between a client and the service application. Subsequent calls in the same session are handled by the same object.

There are 3 context modes in WCF:

  1. PerCall
  2. PerSession (Default)
  3. Single

The default value, PerSession, instructs the service application to create a new service object when a new communication session is established between a client and the service application. Subsequent calls in the same session are handled by the same object. PerSession indicates that each service object handles requests from one client channel. A service configured for private sessions cannot typically support more than a few dozen (or perhaps up to a few hundred) outstanding clients due to the cost associated with each such dedicated service instance.

PerCall creates a new InstanceContext object prior to and recycled subsequent to each call. If the channel does not create a session this value behaves as if it were PerCall. After the method call returns, if the object implements IDisposable, then Windows Communication Foundation calls IDisposable.Dispose on it.

Single creates only one InstanceContext object. It is used for all incoming calls and is not recycled subsequent to the calls. If a service object does not exist, one is created. The singleton service is the ultimate shareable service. When a service is configured as a singleton, all clients get connected to the same single well-known instance independently of each other, regardless of which endpoint of the service they connect to. The singleton service lives forever, and is only disposed of once the host shuts down. The singleton is created exactly once when the host is created.

Which instance context mode to use and when

Per session (Default)

• When you want to maintain states between WCF calls.
• When you don't have very many concurrent connections and don't need to scale up.
• When you have light resource references

Per call

• When you want a stateless services
• When your service holds intensive resources like connection and huge memory objects.
• When scalability is a prime requirement.
• When your WCF functions are called in a single threaded model.

Single

• When you want share global data through your WCF service.
• When scalability is not a concern.



5 comments:

  1. Nice Information
    Get Exclusive Telugu Movie News Online Easily at Pdtvindia.com, You can also read, Latest Telugu Cinema News [url= Telugu Movie News ][/url]

    ReplyDelete
  2. Buy Steroids Online 100% Legal! SDI Labs legal steroids alternative to HGH, Testosterone, Deca Durabolin, Winstrol, Anabolics, Dianabol for bodybuilding.
    best legal steroids

    ReplyDelete
  3. Male Extra Review is considered to have a totally natural formula especially for individuals who are facing the problem of the hair treatment, genetic hair loss.

    ReplyDelete
  4. male enhancement pills that work Does VigRX plus really work? Real reviews from customers, ingredients, side effects, clinical studies and where to buy.

    ReplyDelete
  5. test bank are written by leading nursing educators to reflect the latest standards and technology in the field of nursing.

    ReplyDelete