tags:

views:

231

answers:

2

I am trying to access the singleton instance created by my WCF service but .SingletonInstance seems to be null even after .Open is called on the ServiceHost.

Is there any way to force the ServiceHost to create the instance before the first WCF client request comes in (which presumably automatically spawns the singleton instance)?

+1  A: 

You could make the service call itself...
The instance is indeed only created when a request comes in, you can't access what isn't there yet.

But seriously, try to work around this. What do you need it for that you can't do in the constructor of the implementing class?

Henk Holterman
Thanks for confirming that (and that's an interesting idea about calling itself). I'm trying to add listeners to an event that exists in the singleton so that I can keep the singleton as reusable as possible. Happy to look at an alternative if this is the incorrect approach with WCF. Long story short I'm trying to produce some statistics on a windows form based on the requests coming in.
CuriousCoder
A: 

....you might be able to do crazy things with a custom IInstanceContextProvider...guess this is not worth it though....

Alex