Tuesday, July 31, 2007

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

1 comment:

Unknown said...

could you please give sample code of how to do this in VB?