0

我将实例模式用作 PerSession - 如果客户端对给定方法发出多个请求 - o/p 应该按照下面的代码片段 b/c 递增,实例模式是 PerSession,

但是,每次调用我总是将值设为 1,理想情况下它应该递增。

让我知道我错过了什么

提前致谢...

服务器

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

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

客户

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

1 回答 1

0

你有什么绑定?basicHttpBinding 不支持 PerSession 实例模式,默认为 PerCall。

如果您有 basicHttpBinding 将其更改为 wsHttpBinding 并尝试。

于 2011-01-20T10:18:02.570 回答