what is the purpose of wcf ConcurrencyMode

i am very new in WCF. so often gaze for wcf code & article. after viewing many code i often stuck for very basic things and got no elaborate discussion for the below question. so here are my few basic question....and looking for details discussion with sample situation and with sample code.

what is ConcurrencyMode ?? actually what ConcurrencyMode does.....what it determines?? there are few ConcurrencyMode available and those are Multiple,Reentrant and Single

which concurrent mode one should use in what kind of situation. what will be the best choice. thanks


It depends on what you need. If you need a single instance of your service to be instantiated for the life time of the application you might want to use single. You might do this for instance if instantiating that service was extremely expensive for some reason and it was not called very often so you weren't concerned about multiple threads hitting it at the same time.

    [ServiceBehavior(Namespace = "http://somenamespace", InstanceContextMode = InstanceContextMode.Single)]
public sealed class ServiceWithExpensiveDictionary : IServiceWithExpensiveDictionary, IDisposable
    private DataCacheFactory factory;
    private ConcurrentDictionary<string, DataCache> dataCacheDictionary;

    /// <summary>
    /// Constructor
    /// </summary>
    public ServiceWithExpensiveDictionary()
        factory = new DataCacheFactory();

        dataCacheDictionary = new ConcurrentDictionary<string,DataCache>();

In the code above, I want the ConcurrentDictionary instance to be around for all callers of the service as I'm putting expensive objects into it.

You might use session if you were intending users to have stateful long-running conversations with your api.

You might use per call if your services were stateless and service instantiation was cheap.

It really depends on what you want to do.

There is also a nice question related to this here. It also touches on throttling which you might also be interested in:-

WCF ConcurrencyMode Single and InstanceContextMode PerCall

Need Your Help

Setting a LinearGradientBrush instead of a solid color to a storyboard.targetProperty in a VisualState

wpf storyboard lineargradientbrush

I'm wondering how I can set a Storyboard.TargetProperty to a LinearGradientBrush instead of a solid color.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.