通过单独的应用程序控制服务
我正在编写一个 Windows 服务来进行一些日常处理,并且我希望有一种用户友好的方式与其交互。我将只做基本的事情,例如检查其状态和查看日志,尽管我可能决定也想添加一两个函数调用。经过一些研究后,听起来我需要一个单独的应用程序来执行这些功能,因为该服务将独立于登录到主机的任何用户运行。我的想法是让这个应用程序通过某种接口与服务交互,但我不知道从哪里开始。
让应用程序与单独的服务通信的最简单方法是什么?我会使用 COM、WCF、消息队列还是其他完全不同的东西?我知道可能有几种方法可以做到这一点,所以如果可能的话,我很想听听一些优点和缺点。
编辑:服务和应用程序将在同一台计算机上运行。
I'm writing a windows service to do some daily processing, and I want to have a user-friendly way to interact with it. I'll just be doing basic things like checking its status and viewing logs, though I may decide I want to throw in a function call or two as well. After doing some research, it sounds like I need a separate application to perform these functions, since the service will run independently of any user that's logged into the host machine. My idea is to have this application interact with the service through some kind of interface, but I'm not sure where to begin.
What would be the simplest way to have an application communicate with a separate service? Would I use COM, WCF, a message queue, or something else entirely? I know there are probably a few ways to do this, so I would love to hear some pros and cons if possible.
Edit: The service and the application will both be running on the same machine.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
将 WCF 与 NetNamedPipeBinding(仅允许同一计算机上的 IPC)或 .NET Remoting 结合使用。如果你想快速完成,请选择你更熟悉的技术。如果您不熟悉这些技术中的任何一种,请选择 WCF,因为它是较新的技术,并且您将来很可能会再次使用它 - 因此拥有它的经验将会很有用。
Use WCF with NetNamedPipeBinding (allows only IPC on the same machine) or .NET Remoting. If you want to do it quickly choose the technology you are more familiar with. If you are not familiar with any of these technologies choose WCF because it is newer one and you will more probably use it again in the future - so exeprience with it will be useful.
理想情况下,您将创建一个单独的应用程序并使用 WCF 在您的服务和该应用程序之间进行通信。
但有一种“更便宜”的方法,即使用 HttpListener 实现您自己的简单 Web 服务器。请参阅 http://msdn.microsoft.com/en-us/magazine/cc163879 .aspx
这使得您可以轻松接受一些简单的命令,并且您可以使用任何网络浏览器发送它们。
为了查看日志,为什么不直接跟踪日志文件(例如使用 baretail)?
Ideally you would create a separate application and use WCF to communicate between your service and this application.
But there is a 'cheaper' way which is to implement your own simple Web server using HttpListener. See http://msdn.microsoft.com/en-us/magazine/cc163879.aspx
This makes it easy to accept a few simple commands and you can send them using any web browser.
For viewing logs why not just tail the log files (using e.g. baretail)?
跳过 WCF,只使用普通的 .NET Remoting。容易多了。天知道为什么他们称其为已弃用。
编辑:看到它在同一台 PC 上运行,传输将是命名管道,IIRC WCF 也支持这一点。
Skip WCF, and just use plain .NET Remoting. So much easier. Why they call it deprecated, God knows.
Edit: Seeing it runs on the same PC, the transport would be Named Pipes, IIRC WCF supports this too.