通过网络查询 Windows 服务
我用 C# 编写了一个 Windows 服务,用于收集性能、磁盘和内存信息并将其写入事件日志。 它作为网络服务启用。 我想做的是能够从远程位置收集这些信息。 该服务将在各种客户端计算机上运行,我想定期(每天一次)检索此信息并将它们存储在数据库表中。 我对如何通过网络查询 Windows 服务感到困惑。 换句话说,到底是什么使该服务成为“网络服务”?
我不希望服务直接连接到我的数据库并写入此信息。 但我想从远程计算机启动它,检索信息,然后将该信息写入我的数据库表。
我找不到任何说明联网 Windows 服务的教程。 其中大多数都涉及写入事件日志,而我几乎被困在那里。
这是可行的吗,对于如何完成此类事情有什么建议吗?
I have written a windows service in C# that gathers performance, disk and memory information and writes it to the EventLog. It is enabled as a network service. What I would like to do is be able to gather this information from a remote location. This service will run at various client machines and I would like to retrieve this information periodically (once a day) and store them in a database table. I am confused as to how one can query a windows service over a network. In other words, what exactly makes the service a "Network Service"?
I do not want the service to directly connect to my database and write this information. But I would like to initiate it from a remote machine, retreive the information and then write that information to my database table.
I was unable to find any tutorial that illustrates a networked windows service. Most of them covered writing to event logs and I am pretty much stuck there.
Is this doable, are there any suggestions about how this sort of stuff is done?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果无法选择转移到 WCF Web 服务的其他建议,您可以在 Windows 服务中使用自定义命令进行分配,而不必求助于远程处理。
实际上,您可以发送 128 和 128 之间的整数。 256,然后让您的服务在收到该命令时执行您需要的任何代码,例如将所有信息发送到您的数据库或 Web 服务。
您将能够在需要时从您身边启动它,同时服务愉快地在客户端计算机上运行。
查看此代码项目文章的示例:用 C# 创建基本 Windows 服务< /a>
看一下 OnCustomCammand 方法。
这是 Microsoft 的另一篇示例文章:与 Windows 服务通信
If the other suggestions to move over to WCF Web services are not an option, you can do allot with Custom commands in a windows service without having to resort to remoting.
Effectively you can send an integer between 128 & 256 and then have your service execute whatever code you need it to when it receives that command, like sending all the information to your database or web service.
You will be able to initiate it from your side as and when you need to while the service happily trundles along on the client machines.
Take a look at this code project article for an example: Creating a Basic Windows Service in C#
Take a look at the OnCustomCammand method.
Here's another example article from Microsoft: Communicate With Windows Services
使用 WCF 启用某种形式的 RESTful Web 服务。
请参阅 MSDN 上的 wcf-getting-started,以及特别是使用 WCF 设计和构建 RESTful Web 服务的指南。
Use WCF to enable some form of a RESTful Web Service.
See wcf-getting-started on MSDN, and specially A Guide to Designing and Building RESTful Web Services with WCF.
AFAIK“网络服务”仅意味着它在“网络服务”帐户下运行,该帐户具有与“本地服务”或“系统”帐户不同的权限集。
然而,要将服务公开给网络上的另一台计算机(除了通过服务管理单元 - services.msc 获得的标准停止、启动、重新启动功能之外),您将需要创建服务使用诸如远程处理、Web 服务之类的东西,或者最理想的是 gimel 提到的 WCF。
AFAIK 'Network Service' just means that it is running under the "Network Service" account which has a different set of permission than the 'Local Service' or 'System' accounts.
To expose a service to another machine on the network however (apart from the standard STOP, START, RESTART functionality that you get through the services snap-in - services.msc) you will need to create your service using something like Remoting, Webservices or most ideally as gimel mentioned WCF.