C# WCF服务Http持久连接/会话
我知道HTTP 1.1可以使用基本套接字编程中的“connection:close”头关闭连接。 是否可以使用WCF服务创建持久http连接或会话?例如:C# WCF服务Http持久连接/会话,c#,wcf,C#,Wcf,我知道HTTP 1.1可以使用基本套接字编程中的“connection:close”头关闭连接。 是否可以使用WCF服务创建持久http连接或会话?例如: using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace TestServiceInstance { class ServiceTest :IServiceTest { pr
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();
}
}
}
使用系统;
使用System.Collections.Generic;
使用System.Linq;
使用系统文本;
命名空间TestServiceInstance
{
类ServiceTest:IServiceTest
{
私有整数i=0;
公共服务测试()
{
++一,;
}
公共int PrintNumber()
{
返回i;
}
}
}
使用制度;
使用System.Collections.Generic;
使用System.Linq;
使用系统文本;
使用ServiceTestImplementation.ServiceRef;
命名空间ServiceTestImplementation
{
班级计划
{
静态void Main(字符串[]参数)
{
ServiceTestClient=新ServiceTestClient();
对于(int i=0;i<10;i++)
{
Console.WriteLine(client.PrintNumber());
}
Console.Read();
}
}
}
它总是打印1-但是如果服务实例能够记住它的值,我会喜欢它。。。
谢谢 是的,WCF允许您在客户端调用之间保持会话 您可以使用WCF会话来完成此任务
老实说,大部分说明我都不懂。显然SessionMode=SessionMode.Required不够我认为它可以工作,谢谢-我只是在构造函数中增加了它的值。也许它一直在起作用。