【问题标题】:WCF Service Http Persistent Connection/SessionWCF 服务 Http 持久连接/会话
【发布时间】:2012-02-15 19:31:39
【问题描述】:

我知道 HTTP 1.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 - 但如果服务实例能够记住它的值,我希望它...... 谢谢!

【问题讨论】:

    标签: c# wcf


    【解决方案1】:

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

    您可以使用 WCF 会话来完成此操作。

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

    【讨论】:

    • 说实话,大部分说明我都听不懂。显然 SessionMode = SessionMode.Required 是不够的
    • 我认为它可以工作,谢谢 - 我只在构造函数中增加了它的值。也许它一直在起作用。
    猜你喜欢
    • 2011-06-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多