1

I am trying to figure out why my NetTcpBinding Service is not maintaining state, as expected. (Perhaps I did it wrong)

I have a WCF service with the following structure(simplified):

Message Contract

    [MessageContract]
    public class StreamMetaData
    {
        [MessageHeader] 
        public string Info {get; set;}
        [MessageBodyMember]
        public Stream Data { get; set; }

    }

Contract

    ServiceContract(SessionMode = SessionMode.Allowed)]
    public interface IMyService
    {
        [OperationContract]
        void Init(StreamMetaData metaData);

        [OperationContract]
        StreamMetaData GetMetaData();

    }

Implementation

    [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerSession, ConcurrencyMode = ConcurrencyMode.Multiple)]
    public class MyService : IMyService
    {
        private StreamMetaData _streamMetaData;
        private StreamMetaData StreamMetaData 
        {
            get { return this._streamMetaData; }
            set { this._streamMetaData= value; }

        }

        public void Init(StreamMetaData metaData)
        {
            if (metaData == null)
                throw new ArgumentNullException("metaData");
            try
            {
                this.StreamMetaData = metaData;
            }
            catch (Exception ex)
            {
                throw ex;
            }

        }

        public StreamMetaData GetMetaData()
        {
            return this.StreamMetaData;

        }
    }

Client Side

        MyServiceNetTcp.MyServiceClient client= new MyServiceNetTcp.MyServiceClient ();

        client.Open();

        //metaData is an instance of StreamMetaData initialised somewhere in the code
        client.Init(metaData);

        var currentMetaData = client.GetMetaData(); //Returns null

I followed the MSDN documentation on handling sessions (streams specifically).

Why is it that var currentMetaData = client.GetMetaData(); returns null? Despite initializing it in the first call?

Update:

  • Investigating possibility of having two different bindings: the one for streaming and another for session creation.
tinonetic
  • 7,751
  • 11
  • 54
  • 79

0 Answers0