Recently i came across a situation wherein i had to host a WCF service as a Windows Service.Only after i installed the service using InstallUtil –i “assembly name”,did i realize my folly that i had a misconception regarding the term “Automatic”.What i am referring to the ServiceInstaller.StartType property.The main intent of this property is to start the Service automatically on start of Windows.
So what do i do in run the service while installation?All you need to do add the event AfterInstall for the ServiceInstaller and then call the ServiceController from the eventhandler to start the service.
“The service on local computer started and then stopped. Some Services stop automatically if they are not in use by another services or programs.”
You are all used to debugging and would have most likely than not used the “attach to process ” to debug your service implementation.But what do you do when you get Errors or have to debug the Windows Service installer itself?Bingo, we can always write “System.Diagnostics.Debugger.Launch();” in the OnStart() method and start debugging.Also you can write the errors to the EventLog or dump the Exception to a Log after putting in place a simple try catch!