Instance Management in WCF – Easy WCF
Skip to content

Instance Management in WCF

Definition:

Instance management  defines the binding of service instance to a request received from a client.in otherwords, Instance context mode identifies how long the service instance remains on server.

There are 3 instancing modes in WCF.

  • Percall
    • A new instance of service object is created for every request regardless if the request is coming from same client or different client
  • Persession
    • A new instance of service object is created for each new client session and maintained for the duration of that session
  • Single
    • A new instance of service object is created and handles all request for the lifetime of the application regardless if the request is coming from same client or different client

How to specify the Instancing mode?

You can use servicebehavior attribute and specify instanceContextMode to use it.

PerCall instance Context mode:

Percall Instance mode

  • A new instance of wcf service is created for each request regardless of client
  • Application scalability is better
  • Better memory usage
  • State not maintained between calls
  • Performance could be an issue due to new instance for each service call
  • Concurrency is not an issue
  • If you prefer SOA(Service oriented architecture) then perCall instance can be used
    [service behavior (InstanceContextMode = InstanceContextMode.PerCall]

 

PerSession instance context mode:

PerSession Instance Mode

  • A new instance of wcf service is created for each new clients and maintained for duration of that session
  • State maintained between calls
  • More memory consumption since the service objects remain in memory till client session times out
  • Concurrency is an issue for multi threading client
  • If you want object oriented architecture,PerSession instance can be used
    [service behavior (InstanceContextMode = InstanceContextMode.PerSession]

 

Single instance context mode:

SIngle Instance Mode

  • when the instance context mode for a wcf service is set to Single then only one instance of wcf service is created to handle all request
    [service behavior (InstanceContextMode = InstanceContextMode.Single]
  • State is maintained and shared between request from same client and also from different client
  • Concurrency is an issue
  • Throughput can be an issue

© 2015, admin. All rights reserved.

One thought on “Instance Management in WCF

  1. Pingback: WCF Interview questions (Part – 3) | EasyWCF

Leave a Reply

Your email address will not be published. Required fields are marked *