I am designing a WCF service. I am using netTCP binding. The Service could be called from multi-threaded clients. The multi-threaded clients are not sharing the proxy.
1. WCF Service design question.
Client has to sent these 2 values in every call: UserID and SourceSystemID. This will help the Service to identify the user and the system he belongs. Instead of passing these 2 values in every call, I decided to have them cached with the Service for the duration of call from the client. I decided to have a parameterized constructor for the Service and store these values in the ChannelContext as explained in this article. http://www.danrigsby.com/blog/index.php/2008/09/21/using-icontextchannel-extensions-to-store-custom-data/
Initially I wanted to go with storing the values in the Session and have a method for initialization and termination. But there I found that I need to manually clean up the session in each case. When I am storing values in the channel context, I don’t have to clean it up every time and when the channel closes the values stored are already destroyed. Can somebody please make sure that I am correct in my assumption?
2. Should I use SessionMode? For my contract, I used : [ServiceContract(SessionMode = SessionMode.Required)] and without this service attribute.
Irrespective of my choice, I am always finding a value for : System.ServiceModel.OperationContext.Current.SessionId How can this be explained?
When I say SessionMode.Required, does my InstanceContextMode automatically change to PerSession?
3. InstanceContextMode to be used? My service is stateless except that I am storing some values in the Channel Context as mentioned in (1). Should I use Percall or PerSession as InstanceContextMode?