Q: WCF Instance Management - PerSession Mode I am pretty new in WCF and trying to understand various instance management techniques, I am able to understand Per-Call & Singleton instance mode but i am confused in per session instance mode, In this case for every client a separate session is created right? But its not happening in my case:
My WCF Service:-
[ServiceBehavior(InstanceContextMode=InstanceContextMode.PerSession )]
public class CounterService : ICounterService
{
    int _counter = 0;
    public int GetCount()
    {
        _counter++;
        return _counter;
    }
}

Client Code:-
static void Main(string[] args)
    {
        CounterServiceReference.CounterServiceClient proxy = new     CounterServiceReference.CounterServiceClient();
        CounterServiceReference.CounterServiceClient proxy1 = new CounterServiceReference.CounterServiceClient();
        Console.WriteLine("WCF Instance mode: Per Session");
        Console.WriteLine("Invoking WCF service...");
        Console.WriteLine("Counter: {0}", proxy.GetCount());
        Console.WriteLine("Counter: {0}", proxy.GetCount());
        Console.WriteLine("Counter: {0}", proxy.GetCount());

        Console.WriteLine("---------------------------------------");
        Console.WriteLine("Counter: {0}", proxy1.GetCount());
        Console.WriteLine("Counter: {0}", proxy1.GetCount());
        Console.WriteLine("Counter: {0}", proxy1.GetCount());
        Console.ReadKey();
    }

But, console is displaying result as 1,1,1---1,1,1 but i think it should be 1,2,3---1,2,3
Am i wrong somewhere? Please Help! TIA

A: I think perhaps the best way to explain it is via these diagrams (borrowed from a CodePlex article on the topic):



The main concept to grock is that when a given client creates a proxy to a service in the PerSession mode, repeated calls to that service from that proxy will be calling the same service instance (specific to that client).  This allows you to store some state in your service object for a client, since each client gets their own service object instance.
This contrasts with PerCall and Singleton as follows:
When you create a proxy to a PerCall service, you get a fresh, new instance of the service object every time you invoke a service operation.
When you create a proxy to a SingleTon service, there is only one instance of that service handling all client requests.

A: Session means that you can use the Session object from asp.net, not that the service object = it self is reused. You can save your count value in the Session object and you will not get your expected result. The result will be 1,2,3---4,5,6
