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)?
I know this question is a bit old, but I'm facing a similar problem and think I found a solution. There is an version of the ServiceHost constructor that takes a reference to the instance, rather than the type: http://msdn.microsoft.com/en-us/library/ms585487.aspx#Y342
So you can create the instance first, and then pass it to the ServiceHost constructor. I haven't tried this yet, but it looks like it should do the trick. Be sure to read the remarks about releasing the instance. when you use this constructor.
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?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With