Trouble With WCF InstanceContextMode.PerSession

206 views Asked by At

I'm trying to get to grips with WCF instancing and I'm having trouble with sessions. Either my assumption of how it works is incorrect or I'm missing something.

On my Service contract (implementation not the interface), I've set the service behavior's InstanceContextMode to PerSession. I've got a private string in the service called "word" which is just an empty string, and 2 methods, 1 to set the word variable to a specified value and 1 to retrieve it.

I've added a service reference in an MVC app, then performing the following calls:

  • GetWord()
  • SetWord("test")
  • GetWord()

The first call returns an empty string as I expected. SetWord is updating the private variable and retuning that value as I expected. However the 2nd call to GetWord() is returning an empty string, I would have expected it to return "test".

If I change the InstanceContextMode to "Single", I get "test" from the end call to GetWord (As I would expect), but I don't understand why I wouldn't get the same from PerSession.

Can anyone help me understand where I'm going wrong?

0

There are 0 answers