tags:

views:

40

answers:

1

I have here what would appear to be a simple task; listing all the instances of a service object actively managed by a WCF ServiceHost at any particular time.

For example, my service contract interface is IFooService and the implementation is FooService (with a per-session behaviour). On the service side I simply instantiate the service host using ServiceHost(typeof(FooService)) and open it. Sessions are created, destroyed, and operations called as normal by clients - and for the most part, the fact that this functionality is hidden is good.

However, my goal is to expose a method in the class that declares the ServiceHost that lists all currently active instances of IFooService (or similarly FooService). Having the class track its own instances is possible, but doesn't seem too elegant. Is there any in-built method for WCF to return a list of all service object instances managed by a ServiceHost?

+1  A: 

I can't think of how to get the instances themselves, but the count can be gotten from the instances performance counter.

Jason Punyon
Thanks. Unfortunately, I need more than just the count. My current workaround is to store a list of WeakReferences pointing to all instances of the class, seems to be working well enough, perhaps not ideal though.
Noldorin