views:

407

answers:

5

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

+5  A: 

Start / 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.

james
+1 We did the same for our service
Rashmi Pandit
Is there any way I can make this setting inside the code of the Service. After deploying the service at client end.. I don't want him to configure it with above settings manually.
Sumeet
+2  A: 

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.

JohannesH
A: 

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.

msvcyc
A: 

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.)

the_ajp
+1  A: 

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.

Morbia