简体   繁体   English

WCF服务Http持久连接/会话

[英]WCF Service Http Persistent Connection/Session

I am aware that HTTP 1.1 can close a connection using the "Connection: close" header in basic socket programming. 我知道HTTP 1.1可以在基本套接字编程中使用“连接:关闭”标头关闭连接。 Is it possible to create a persistent http connection or session using WCF service? 是否可以使用WCF服务创建持久的http连接或会话? For example: 例如:

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();
        }
    }
}

It always print 1 - but I would like it if the service instance can remember its value... Thanks! 它总是打印1-但如果服务实例可以记住它的值,我希望它...谢谢!

Yes, WCF allows you to persist sessions between client calls. 是的,WCF允许您在客户端调用之间保留会话。

You can use WCF sessions to accomplish this. 您可以使用WCF会话来完成此操作。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM