In this article, we are going to see how to host Windows service in WCF and automatically start and stop the Service by using Button click events.
Introduction
In this article, we are going to see how to host Windows service in WCF and automatically start and stop the Service by using Button click events.
Let us go through this application step by step
Step1: I suggest you to go through this article
http://msdn.microsoft.com/en-us/library/ms733069.aspxImplement the same. Actually i need to explain a lot of thing here,so i suggested you to go through this article.
Step2: Create a new Web For application->name it->Add the service reference to it.
In the Form design, add 2 button's one as start,another as stop and put a label to it.
Step3: Now give a reference to System.ServiceProcess.
Now add your service reference to generate the proxy and we are going to use ServiceController method to automatically start and stop the service.
Step4: Now ,in the Form load event write these lines

Scratched content contains computer name.Because its confidential i can't disclose infront of you people. Service name is the same whatever i suggested you people to read. We are checking the status, if it suggests that service is running then there is no point in stopping the service.
Step5: Now let see what we are going to do in start and stop functionality.

I implemented the same functionality whatever i did in form load event.
I hope you people like this article.
Reference:
http://msdn.microsoft.com/en-us/library/ms733069.aspx