开发者

Sending message to windows service by web page

How could I do this with no access denied problem?

I have a windows service:

protected override void OnCustomCommand(int command)
{        
    if (command == 1)
    {
      foreach (Process traceProcess in Process.GetProcessesByName("notepad.exe"))
      {
        tra开发者_如何转开发ceProcess.Kill();
      }                     
    }        
}

when I do this:

ServiceController sc = new ServiceController("ProjectManager");
if (sc != null)
    sc.ExecuteCommand(1);

From a windows forms it works, but not from a web page, I get access denied on sc.ExecuteCommand.

What is the best way for a web page to talk to a service?


I got a workaround for the permission problem; sockets.

So my service opens a local port (not available to any other machine, only local)

Then in my web page I connect to this socket and send the byte I want, and in return the service executes the code I want.

If anyone asks, I can post example code.


You need to check the permissions of the the application pool identity.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜