I am aware that HTTP 1.1 can close a connection using the “Connection: close” header in basic socket programming.
Is it possible to create a persistent http connection or session using WCF service? 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!
Yes, WCF allows you to persist sessions between client calls.
You can use WCF sessions to accomplish this.
http://msdn.microsoft.com/en-us/library/ms733040.aspx