locked
Start Stop Window Service Remotelty RRS feed

  • Question

  • Hello,

    I am not sure if this question belongs in this forum. If not i apologize.

    I want to control (stop and start) a window service which resides outside my domain. I created a WCF service and deployed it on the server where the Window service is running so that i can control it with WCF client.

    My question is what security access should i give to the WCF service or the window service, so that i can be able to start and stop the window service from outside the domain with the WCF client.

    Just a point to note is, my WCF client is able to communicate with the WCF service which I tested with a test operation. But when it comes to stopping or starting the service, i get an error "Cannot open <ServiceName> service on computer '.'"

    I appreciate your help and thank you in advance.
    Monday, October 5, 2009 4:45 PM

All replies

  • Greetings,

    Inside the wcf service you need to create a method for as per sample code which is given below. You need to use the namespace which is given below

    using System.ServiceProcess;

    [ServiceContract]
    public interface IStartService
    {
       [OperationContract]
       void StartService();

       [OperationContract]
      void StopService();
    }

    public class Service Imp : IStartService
    {
                 ServiceController controller  = new ServiceController();
       public void StartService()
       {
               controller.MachineName = ".";
               controller.ServiceName = "Service Name";

              // Start the service
              controller.Start();
       }

      public void StopService()
      {
         // Stop the service
        controller.Stop();
      }
    }


    When you expose the wcf service to the outside world , we start and stop the window service using the wcf service. I would suggest that you would eventlog , so that we can trace the activities of window service.  Please ensure that the window service and wcf service hosting are done in the same machine or the server.  Ensure that you are tracking the activity the using the svctraceviewer.

    Important Point :Also ensure the window serve startup should be set to automatic or Manuel.  Since you are calling the wcf method , I would suggest you would use automatic startup for the window service

    Take Care

    PL
     
    • Edited by PROGRAMMERLIVE Thursday, October 15, 2009 10:07 AM changed the text
    Thursday, October 15, 2009 9:36 AM