Click here to Skip to main content
15,881,204 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi All,
I am working on a migration project in which I am rewriiting a web service (.asmx) to a WCF service.

My old service has some code like this.
Application[strSession] = LstUserSessionTrack;


The above code is using the Application object of ASP.NET to maintain state. Application object is not available in WCF.

I am looking for some object in WCF which is equivalent to the Application object.I want to implement state management in WCF.

Kindly suggest.

Thanks.

"Happy Coding"
Posted

1 solution

Hi,

You don't have direct equivalent in WCF for an Application.

But you can maintain state per session with InstanceContextMode.PerSession in ServiceBehavior like this:

C#
[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerSession)]
public class Service : IService
{
}


WCF will create instance for each session initiated by your clients. You can control on a service contract which operation is initiating
[OperationContract(IsInitiating = true)]
and wich is terminating
C#
[OperationContract(IsTerminating = true)]


You can also make your service implementation class disposable, so WCF will call Dispose method whenever session is ended.

Last thing - you have to choose binding that supports sessions, like NetHttpBinding for instance.

Good luck,

Michael Parshin
 
Share this answer
 
v3
Comments
TapasU 27-Jun-13 1:30am    
Thanks Michael. I will try your solution and will get back if this gets going.
Thanks once again.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900