开发者

Obtain an reference to a wcf service

I have a wcf service singleton type, and in the same application an ASP page that 开发者_如何学Gouses a service-specific function.

As I can get a reference to the service instance created, not to run twice the manufacturer's service?

My service is published on IIS


I'm guessing you are saying that you have a service that is supposed to be a singleton and because you're in the same AppDomain you can simply create an instance as well.

If you own the service code you can make it a singleton using the Singleton Pattern (there are a number of ways to do that in .NET and Jon Skeet has a list of them here).

Then you need to deal with how does WCF get hold of the instance? In that case there are two options:

  1. Use a ServiceHostFactory and hand the instance to the ServiceHost you create
  2. Implement IInstanceProvider and plumb that in

If you don't control the service class then there is nothing you can do to prevent people creating instances but you can wrap the class in your own singleton and stipulate access must only be via the singleton so it is less likely that someone will create a second instance

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜