我已经阅读了有关代码项目和MSDN的WCF会话的一些文章,并根据我发现的这个图表:
如果我执行下面的代码,如果从同一个实例调用,i
的值必须保持增加,但它不会:
[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerSession)]
// NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "Test" in code, svc and config file together.
// NOTE: In order to launch WCF Test Client for testing this service, please select Test.svc or Test.svc.cs at the Solution Explorer and start debugging.
public class Test : ITest
{
int i = 0;
public int DoWork()
{
i++;
return i;
}
}
static void Main(string[] args)
{
ServiceReference1.TestClient c = new ServiceReference1.TestClient();
while (true)
{
Console.WriteLine(c.DoWork(new ServiceReference1.DoWorkRequest()).DoWorkResult);
Console.ReadLine();
}
}
当我使用Single
时,它会不断增加。
我的问题是,我如何利用会话以每会话的方式实现这一目标(而不是像单一的那样)?