Я новичок в WCF и написал пример службы WCF, которая использует InstanceContextMode.Когда я использую PerSession, значение моего счетчика не увеличивается.Почему он не использует один и тот же экземпляр для каждого вызова службы.Ниже приведен мой код
[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerSession)]
public class Service1 : IService1
{
int count;
public int Add(int a, int b)
{
count++;
return a + b;
}
public int GetCount()
{
return count;
}
}
WebConfig
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior>
<!-- To avoid disclosing metadata information, set the values below to false before deployment -->
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
<!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
<protocolMapping>
<add binding="basicHttpsBinding" scheme="https" />
</protocolMapping>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
Client.cs
DemoWCFService.Service1Client client = new DemoWCFService.Service1Client();
Console.WriteLine(""+ client.Add(10,20));
Console.WriteLine("" + client.Add(10, 20));
Console.WriteLine("" + client.Add(10, 20));
Console.WriteLine("" + client.GetCount());
Console.ReadKey();
Пожалуйста, помогите мне с этим.