tags:

views:

169

answers:

3

Does anyone know of a framework that would allow me to easily host and configure WCF services within a Windows Service?

Originally I had developed a system where a single host application contained one Windows Service per service host so that the administrators could manage these services individually in the Services applet.

However, other systems are coming on-line with an increasing number of WCF services that would need to be hosted this way and there is growing concern that this will become too complex to manage through the Services applet.

The requirements coming from above are that we need the ability to configure what services are hosted within the Windows Service, start and stop them as required, and allow for easy deployments.

I believe that within the service we could host a management WCF service that would allow us to control the behaviour of the other services but if someone has already created a framework for doing this I am more than happy to use the wheel that has already been invented.

+2  A: 

Well, hosting a WCF service in a Windows NT Service isn't really all that hard - so I don't think there's a big "framework" available for that...

Basically, you need to

  • declare a ServiceHost variable for each WCF Service you want to host
  • in the OnStart() method override of the NT Service, you instantiate and open the service hosts
  • in the OnStop() method of the NT Service, you close the service hosts again

That's about all there is - so what aspect did you want to delegate to a framework in this scenario? What other aspects or problems do you have that need to be handled?

If you want to influence separate service instances inside a single NT Service, you'll have to check into the OnCustomCommand method override on your NT Service class.

From the outside, you can create a ServiceController and then call ExecuteCommand on that controller. Unfortunately, you can only send in a single int as a parameter.

So I guess in this case, you'd have to define e.g. a "service constant" for each service, e.g. const int MyService1 = 10; const int MyServive2 = 20; and then use that base service constant to start the WCF service, that base constant + 1 to stop it, or something along those lines.

marc_s
That is what I have at the moment but we want to host multiple services from a single Windows Service but dynamically manage which WCF services are running within that service
Ian Johnson
ah okay, so you want to be able to signal to the NT Service to shut down or restart a hosted WCF service? Sounds like a good idea, but I don't think there's any framework out there (yet) - up to you to create it and share it with the WCF world !
marc_s
Create a 'management' or 'admin' host running within the same service that has the capability to close the other hosts. That should do the trick...
MattK
I think it looks like I will have to do that one, hopefully my boss will let me stick it on Codeplex or somewhere
Ian Johnson
A: 

This comes down to personal opinion. I see no problem with controlling a hundred different services via the standard MMC snap-in. It also allows a network admin to manage them centrally for the entire domain using WMI, PowerShell, commercial tools, etc. If you roll your own management system, you give up this kind of easy centralised control.

As for deployment, just create one custom action to install all the services in one go.

Christian Hayter
A: 

Seems like this app matches some what you're looking for. It can dynamically host wcf services and has a UI for managing it.

alt text App : http://www.wcfstorm.com/wcf/getting-started-with-wcfstormhost.aspx

Fantastic, hadn't heard about that before, thanks
Ian Johnson