locked
Signal R Webclient to Windows Service RRS feed

  • Question

  • User-1708320409 posted

    Hi There,

    i didn't use signal R before in projects. And would like to do the following.

    Multiple users in our web application(but not all). Should get a button. That sends a message(through Signal R) to a windows Service /or console application to trigger an action. 

    After the Action is finished the application shoud respond to the client that its done.

    Does anybody has a example code.

    Thnx

    Tuesday, October 10, 2017 9:47 AM

Answers

  • User1771544211 posted

    Hi vdboots,

    My problem is that is that the Windows Service is on a other computer.

    Please try use the following code to start windows services on remote server.

           private string servicestart(string compname, string service)
            {
                ServiceController sc = new ServiceController();
                sc.ServiceName = service;
                sc.MachineName = compname;
                string result = sc.Status.ToString();
    
                if (sc.Status == ServiceControllerStatus.Stopped)
                {
                    try
                    {
                        sc.Start();
                        sc.WaitForStatus(ServiceControllerStatus.Running);
                        result = sc.Status.ToString();
    
                    }
                    catch (InvalidOperationException)
                    {
                        // do something
                    }
                }
                return result;
            }
    
    
            string status = servicestart("computerName", "Service");

    Note that : make sure you're able to start that service remotely using the current permissions and credentials.

    Best Regards,

    Jean

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, October 12, 2017 3:16 AM

All replies

  • User1771544211 posted

    Hi vdboots,

    What's the problem do you face now?

    If you are having problem with Calling the windows service from the Web Application. Here is a good article which shows how to do this, please take it as reference.

    http://www.csharp-examples.net/restart-windows-service/

    If you are having problem with how to use SignalR, please check the following tutorial.

    https://www.asp.net/signalr

    Or you can just use ajax to achieve your requirements instead of using SiganlR.

    Best Regards,

    Jean

    Wednesday, October 11, 2017 2:06 AM
  • User-1708320409 posted

    Hi Thanks For your Answer, 

    My problem is that is that the Windows Service is on a other computer. And i cannot get one to one signals working from my frontend. I would like to trigger a action in the service.

    Wednesday, October 11, 2017 6:38 AM
  • User1771544211 posted

    Hi vdboots,

    My problem is that is that the Windows Service is on a other computer.

    Please try use the following code to start windows services on remote server.

           private string servicestart(string compname, string service)
            {
                ServiceController sc = new ServiceController();
                sc.ServiceName = service;
                sc.MachineName = compname;
                string result = sc.Status.ToString();
    
                if (sc.Status == ServiceControllerStatus.Stopped)
                {
                    try
                    {
                        sc.Start();
                        sc.WaitForStatus(ServiceControllerStatus.Running);
                        result = sc.Status.ToString();
    
                    }
                    catch (InvalidOperationException)
                    {
                        // do something
                    }
                }
                return result;
            }
    
    
            string status = servicestart("computerName", "Service");

    Note that : make sure you're able to start that service remotely using the current permissions and credentials.

    Best Regards,

    Jean

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, October 12, 2017 3:16 AM