trouble configuring WCF to use session

Posted by Michael on Stack Overflow See other posts from Stack Overflow or by Michael
Published on 2010-06-16T08:31:12Z Indexed on 2010/06/16 8:52 UTC
Read the original article Hit count: 417

Filed under:
|
|

I am having trouble in configuring WCF service to run in session mode. As a test I wrote this simple service :

[ServiceContract]
public interface IService1
{
    [OperationContract]
    string AddData(int value);
}

[ServiceBehavior(InstanceContextMode=InstanceContextMode.PerSession)]
internal class Service1 : IService1,IDisposable
{
    private int acc;

    public Service1()
    {
        acc = 0;
    }

    public string AddData(int value)
    {
        acc += value;
        return string.Format("Accumulator value: {0}", acc);
    }

    #region IDisposable Members

    public void Dispose()
    {           
    }

    #endregion
}

I am using Net.TCP binding with default configuration with reliable session flag enabled. As far as I understand , such service should run with no problems in session mode. But , the service runs as in per call mode - each time I call AddData , constructor gets called before executing AddData and Dispose() is called after the call. Any ideas why this might be happening?

© Stack Overflow or respective owner

Related posts about c#

Related posts about wcf