WCF服务Http持久连接/会话

本文关键字:连接 会话 服务 Http WCF | 更新日期: 2023-09-27 18:24:39

我知道HTTP1.1可以在基本套接字编程中使用"connection:close"头来关闭连接。是否可以使用WCF服务创建持久http连接或会话?例如:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace TestServiceInstance
{
    class ServiceTest  :IServiceTest
    {
        private int i = 0;
        public ServiceTest()
        {
            ++i;
        }
        public int PrintNumber()
        {
            return i;
        }
    }
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ServiceTestImplementation.ServiceRef;
namespace ServiceTestImplementation
{
    class Program
    {
        static void Main(string[] args)
        {
            ServiceTestClient client = new ServiceTestClient();

            for (int i = 0; i < 10; i++)
            {
                Console.WriteLine(client.PrintNumber());
            }
            Console.Read();
        }
    }
}

它总是打印1,但我希望服务实例能记住它的值。。。谢谢

WCF服务Http持久连接/会话

是的,WCF允许您在客户端调用之间保持会话。

您可以使用WCF会话来实现这一点。

http://msdn.microsoft.com/en-us/library/ms733040.aspx