Instancing in WCF - Query specific to Mode.PerSession

113 views Asked by At

I am using Instancing mode as PerSession - If a client makes multiple request for a given method - o/p should be incremented as per below code snippet b/c Instancing mode is PerSession,

However I am always getting value as 1 for every call, ideally it should be incremented.

Let me know what I am missing

Thanks in advance...

Server

[ServiceContract]
public interface IServer
{
 [OperationContract]
  int GetData();
}

[ServiceBehavior(InstanceContextMode=InstanceContextMode.PerSession)]
public class Service1 : IServer
{
  int count = 0;
  public int GetData()
   {
     count++;
     return count;
   }
}

Client

ServiceReference1.IServer obj = new ServiceReference1.ServerClient();
Console.WriteLine(obj.GetData());
Console.WriteLine(obj.GetData());
1

There are 1 answers

3
Suhumar On

what is the binding you have ? basicHttpBinding does not support PerSession instance mode it defaults to PerCall.

If you have basicHttpBinding change that to wsHttpBinding and try.