WCF会话:如何使用会话

时间:2015-06-18 14:25:31

标签: c# wcf session

我已经阅读了有关代码项目和MSDN的WCF会话的一些文章,并根据我发现的这个图表:

enter image description here

如果我执行下面的代码,如果从同一个实例调用,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时,它会不断增加。 我的问题是,我如何利用会话以每会话的方式实现这一目标(而不是像单一的那样)?

0 个答案:

没有答案