开发者

Is it possible to get a reference to a WCF ServiceHost Singleton Instance before the first WCF client request comes in?

开发者 https://www.devze.com 2022-12-22 22:02 出处:网络
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.

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 sing开发者_JAVA技巧leton 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?


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


You can use the constructor of your class and store instance object when it is created by wcf servicehost

0

精彩评论

暂无评论...
验证码 换一张
取 消