How to Maintain per-Client State in a WCF Service?

Posted by tbischel on Stack Overflow See other posts from Stack Overflow or by tbischel
Published on 2010-06-10T00:51:08Z Indexed on 2010/06/10 1:42 UTC
Read the original article Hit count: 497

Filed under:
|
|

I've created a WCF service in which I would like it to maintain state between calls from the client. I figured the easiest way to do this was to add this attribute to the service:

[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerSession)]

since this is supposed to keep a separate service alive for each client over the life of the client proxy (or timeout in the extreme case). I also added a test function that tracks a list of user inputs, and spits out a concatenated string with all the inputs over the life of the service.

When I run this in the test client generated by visual studio, I find that the list I was using to hold past data is reset with each call. Is there something else I need to do to maintain state per session?

© Stack Overflow or respective owner

Related posts about c#

Related posts about wcf