WCF Memory Performance InstanceContextMode

I've been learning my way around WCF and I've got a question regarding the InstanceContextMode.

Correct me if I'm wrong, but the WCF will instantiate your object, then call the service method on it per call by default.

You can then set it to be PerSession or Single.

It seems to me that it would make more sense to have something between session and call which could reuse your object. I.e if my service were reentrant, then I could open connections to databases etc. in the constructor, then leave the object in memory to answer calls concurrently.

But in the current WCF implementation, it seems that it will always recreate the object no matter what.


The samples here


show how to use extensibility to exercise more fine-grained control over how instances are created and destroyed (e.g. pooling).

Even while using PerCall instancemode, you can still re-use heavy data structures if those are static. Remember, static objects will have the lifetime of the appdomain so lets say if you initialized a static object (which required an expensive operation), it will be visible to other WCF per call instances as well and will remain alive until the appdomain is destroyed (the lifetime of appdomain depends upon your server settings).

Be careful to handle the synchronization issues and also NOT to have any information in this static class which you DON'T want to share between all your per call instances.

My $0.02

Need Your Help

How to switch from LocalDB instance to SQL Expres?

entity-framework visual-studio-2012 code-first sql-server-express

I started a new project to try to implement the repository pattern, but I've somehow gotten myself mixed up in an ouroboros of programming confusion. I created an SQL Express database and built an ...

Dynamic ViewModel Generation in asp.net mvc 3

asp.net-mvc-3 c#-4.0

I am attempting something very ambitious on asp.net MVC 3 backed with C sharp 4.0 . Without further trash talk I will get

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.