I want to be able to save variables between calls to my WCF service for various reasons. I have the following, which works, but I read that using "Single" is a really bad idea. This is really a prototype and nothing critical, but it does have multiple users and I'm afraid single will mean it sets the same variables across all user sessions. Can someone confirm/deny this? It doesn't work at all when I set it to PerSession, which is logically what I would think I would want.
<ServiceContract(Namespace:="")> _
<AspNetCompatibilityRequirements(RequirementsMode:=AspNetCompatibilityRequirementsMode.Allowed)> _
<ServiceBehavior(InstanceContextMode:=ServiceModel.InstanceContextMode.Single, ConcurrencyMode:=ServiceModel.ConcurrencyMode.Single)> _
Public Class MyServices
Public testint As Integer = 0
<WebGet()>
<OperationContract()> _
Public Function test1() As Boolean
testint = 42
return true
End Function
<WebGet()>
<OperationContract()> _
Public Function test2() As Integer
return testint
End Function
End Class
I read something about a "Durable" service, but VS2010 only lets me choose PerCall, PerSession and Single for the InstanceContextMode.
Check out the WCF Documentation about Session handling (MSDN) If you´re working on a prototype you can get along building a static dictionary, in which you can dump your values in combination with a session key