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
source
share