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