EugeneK\

I need to host a service. The service should have InstanceContextMode.PerSession . When created the service needs to be initialized with some other objects. In any other case I would pass this parameter to constructor and that would be it. In WCF I don't have control on when and how service is created.

I had a look at IInstanceProvider interface but it doesn't solve my problem. If I hookup custom implementation of IInstanceProvider then how do I control instance contex mode to be PerSession Every single sample of IInstanceProvider interface implementation is singletone pattern implementation. That's easy. But what about PerSession context mode



Re: Windows Communication Foundation (Indigo) How to initialize a service with parameters?

Brian McNamara - MSFT

I think you do want IInstanceProvider. The fact that the samples do singletons is I think just a quirk of the samples we wrote. This extensibility point should work just fine for InstanceContextMode.PerSession; GetInstance will be called just once per session, I think (the sample at http://msdn2.microsoft.com/en-us/library/ms751409.aspx suggests this directly). Have you tried it




Re: Windows Communication Foundation (Indigo) How to initialize a service with parameters?

EugeneK\

Hi Brian,
Thanks for your reply.
I did try to implement IInstanceProvider but GetInstance method gets called every time client calls any method of the service. It looks like it ignores PerSession attribute once you hookup your own InstanceProvider. So if I just create new service instance whenever
GetInstance called I get PerCall service behavior regardless of the fact that my services has ContextMode.PerSession assigned. Any idea how to solve this problem




Re: Windows Communication Foundation (Indigo) How to initialize a service with parameters?

Brian McNamara - MSFT

Ah, in that case, does it get called with the same InstanceContext object when part of the same Session You can just keep a dictionary of service objects keyed by InstanceContext, and return an existing object from the dictionary if this is an InstanceContext you've already seen.




Re: Windows Communication Foundation (Indigo) How to initialize a service with parameters?

EugeneK\

Nope, InstanceContext object is different for each consequent call. There is even more. Once call is completed ReleaseInstance called for custom IInstanceProvider. It looks like WCF completely ignores any InstanceContextMode if you have custom IInstanceProvider. If it's a feature of WCF rather than bug then how am I supposed to support PerSession mode with custom object construction



Re: Windows Communication Foundation (Indigo) How to initialize a service with parameters?

Brian McNamara - MSFT

What binding are you using If the binding does not support Session, then 'PerSession' falls back to 'PerCall', so maybe that explains the behavior you are seeing