WCF Instance Management - PerSession Mode

I am new to WCF and trying to understand the various methods of managing instances, I can understand the instance mode of Per-Call and Singleton, but I am confused in session session mode. In this case, for each client, a separate session is correct? But this does not happen 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 the console displays the result as 1,1,1 --- 1,1,1, but I think it should be 1,2,3 --- 1,2,3 Am I something wrong? Please help! TIA

+4
source share
2 answers

I think that perhaps the best way to explain this is through these diagrams (borrowed from the CodePlex related article ):

WCF Per SessionWCF Per Callenter image description here

grock , - PerSession, ( ). , .

PerCall Singleton :

- PerCall, , , .

- SingleTon, .

+4

, Session asp.net, service = it self. Session, . 1,2,3 --- 4,5,6

+2

All Articles