Managing your WCF Service Context & State

Hi Folks,

when you create a host for your service,this host manage the context of the service and its states,for this reason,you have to take care how can you configure your host to keep your service under control without any issues regarding the security or performance.

One point regarding the Service performance which is the Service Context:did u ask your self if 1000 Clients call your service ? how manay instances will be created from your service ?

To answer this question,you have to know which mode are your setting your service to work with.

1) Per Session Mode :

How to Implement : Mark your service class with this attribute

C# : [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerSession)]

Answer : 1000 sessions will be created.

2) Per Call Mode :

How to Implement : Mark your service class with this attribute

C# : [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)]

Answer : Per call the host will create an instance for your service.
This mode give better performance incase the client still opened and not active rather than the prev. mode.

3) Single Mode :

How to Implement : Mark your service class with this attribute

C# : [ServiceBehavior(InstanceContextMode = InstanceContextMode.Single)]


Answer : 1 instance and all clients can share data between them.

Hope this helps.


Regards,
Moustafa arafa

Leave a Reply

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

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>