views:

305

answers:

1

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.

+2  A: 

The samples here

http://msdn.microsoft.com/en-us/library/aa967565.aspx

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

Brian