Reputation: 3067
I have a Windows Service hosting a WCF service. If something goes really wrong in my WCF service I'd like to stop the Windows Service. I could try and force it to stop by shelling out and using net stop but is there a 'nicer' way to do this?
WCF is run the usual way from windows service:
protected override void OnStart(string[] args)
{
if (serviceHost != null)
{
serviceHost.Close();
}
///WCF service hosted
serviceHost = new ServiceHost(typeof(XXXService));
serviceHost.Open();
}
Upvotes: 3
Views: 1248
Reputation: 7067
In the past, we have implemented our self-hosted WCF Windows Services with a “Service Host Controller” class that holds references to the ServiceHost objects and is therefore responsible for “starting”/opening and “stopping”/closing the service host object. In addition, the “Service Host Controller” class implements a delegate that allows the hosted objects to call back into the controller and initiate a graceful shutdown.
Upvotes: 1