Search code examples
c#.netwcfnettcpbinding

WCF InstanceContext Single or InstanceContext PerSession with static member


I am designing and PubSub system with WCF (for learning purposes) using netTcpBinding and Duplex Communication. In my publisher ServiceContract I have a dictionary that I need to share between all sesions, and list that I need to be session specific.

What would be the best option for this case?

  1. InstanceContext.PerSession - with dictionary as static member, and list as private member
  2. InstanceContextMode.Single - dictionary as private, list will transfered to dictionary(key -user, value - user's list)

Another question I have, I am comming from NodeJS/EventMachine background, and I want to don't what will be more performance-wise for this kind of service - ConcurrenyMode.Multiple or ConcurrencyMode.Reentrant?


Solution

  • Firstly - ConcurrencyMode.Reentrant is single threaded so will end in locks, you're best off with ConcurrencyMode.Multiple (provided you've taken the necassary steps within your code to protect against usual threading issues)

    Regarding your instancecontextmode - I would believe you're better off with PerSession than Single in the scenario you've described.

    Here helps a bit too - http://msdn.microsoft.com/en-us/library/system.servicemodel.concurrencymode.aspx