Hi
We have an windows service written in .net, that is hosting WCF service. My question is, Is it possible to monitor and restart service on any fault, in other world I want my service to be restarted automaticaly on any fault.
Thanks a lot
views:
407answers:
5Start / Control Panel / Services / right-click your service / Properties / First failure : restart the service / Second failure : restart the service / Subsequent failure : restart the service.
Should do it.
Go into the service manager in the OS, right-click your service and choose properties. There you'll find a recovery tab which lets you define behavior on crashes.
You could write another service like a watcher service that will monitor this core service & will re-start it when stopped. However, nothing can be done if the watcher service is stopped.
I think you should think about the design of your service. It should be a host to the wcf process. You could make 3 threads:
Main thread (only stops on v FATAL error)
ExceptionHandler thread (handles "expected" exceptions and does logging and takes care of the WCFHost thread dying)
WCFHost thread (Hosts the WCF Service and can die as often as it likes the ExceptionHandler can take care of this now.)
Within single windows service there can be multiple WCF services. You can handle Faulted event of the ServiceHost class for individual WCF service and re-initialize it.