WCF methods sharing a dictionary

Posted by YeomansLeo on Stack Overflow See other posts from Stack Overflow or by YeomansLeo
Published on 2011-10-18T23:46:21Z Indexed on 2012/06/02 4:40 UTC
Read the original article Hit count: 174

Filed under:
|
|
|
|

I'm creating a WCF Service Library and I have a question regarding thread-safety consuming a method inside this library, here is the full implementation that I have until now.

namespace WCFConfiguration
{
    [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall, ConcurrencyMode = ConcurrencyMode.Single)]
    public class ConfigurationService : IConfigurationService
    {
        ConcurrentDictionary<Tuple<string,string>, string> configurationDictionary = new ConcurrentDictionary<Tuple<string,string>, string>();

        public void Configuration(IEnumerable<Configuration> configurationSet)
        {
            Tuple<string, string> lookupStrings;
            foreach (var config in configurationSet)
            {
                lookupStrings = new Tuple<string, string>(config.BoxType, config.Size);
                configurationDictionary.TryAdd(lookupStrings, config.RowNumber);
            }
        }

        public void ScanReceived(string boxType, string size, string packerId = null)
        {

        }
    }
}

Imagine that I have a 10 values in my configurationDictionary and many people want to query this dictionary consuming ScanReceived method, are those 10 values be shared for each of the clients that request ScanReceived? Do I need to change my ServiceBehavior?

The Configuration method is only consumed by one person by the way.

© Stack Overflow or respective owner

Related posts about c#

Related posts about .NET