WCF Behavior of Service

Well there is much more knowledge and literature we can found on the Internet of WCF programming model, check this link, me not going to detail of what the wcf is , but in this blog i am going to show how we can create or maintain a different behavior of our  WCF service on IIS, for example we need only a single instance of our service, so we can do in WCF , these singleton pattern can robust service on the SOA architecture where we need to hav a service oriented development, WCF is positioned to take full advantage of single instance on any host. service Behaviour actually tell us how service behave and it is only applicable at the class level in the service.
There are different elements by which WCF architecture can control the service behavior. Let start to analyse all of them.

  • Instancing: Controls new object creation and it control the object lifetime on service called , The default is

PerCall, w. Generally, in session-oriented services, providing either PerSession or Shareablemay provide better performance.It tell that when and how new service object is created.


Now If we choose InstanceContextMode to Percall then a new service object is created and recycle the subsiquent on each call. Persession create a object of service as per session.Single is like a singleton which creaete only a single instance for all incoming calls and not recycle.Only created when no object is found.

  • Concurrency: Controls threading behavior for an object and whether it supports reentrant calls. Valid only if the Instancing property is not PerCall.

Now If we Select Multiple then our service instance is multi threaded, any other threads can change our service object at any time, in this case we need to handle the syncronizaiton, Reentrant option make our service instance single threaded and in that case our service can accpets calls when we need to call another service over the channel, but for this option our object state should be consistaant in the last case of Single our service mode is singel threaded and in this case our service will not accept reentrant calls.

  • Throttling: Managed through configuration, when concurrency allows for multiple calls, to limit the number of concurrent calls, connections, total instances, and pending operations.
  • Transaction: Controls transaction aspects such as autocompletion, isolation level, and object recycling.
  • Session management: Provides automatic session shutdown or overrides default behavior.Thread behavior: Forces the service thread to have affinity to the UI thread; this is helpful if the underlying service host is a WinForms application and updates to controls on that formmay happen in the service implementation.

OperationBehavior Attribute :
OperationBehvior attribute give us more control over the wcf service operation level, one thing to note here is that these implementation is only applied to class method not on interface in the service .below are the attribute by which we can control.


Transactional: Provides for autocompletion along with transaction flow and the required and supported options

Caller identity:When binding supports, provides the ability to execute under the caller’ s identity

Object recycling: Provides for overriding the InstanceModemode of the ServiceContractBehavior


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s