从 Windows 服务和控制台应用程序访问相同的运行代码?
我有一个构建为 Windows 服务和 ac# 库程序集 (.dll) 的应用程序。为了管理和维护此服务,我想添加运行命令行应用程序的功能,该应用程序会告诉您上次的时间服务存档的文件、下次计划执行此操作的时间、上次运行的状态以及服务创建的文件的位置。
编写可以与其他应用程序共享数据的服务和库的最佳架构是什么? 我正在使用.net 2.0。
I have an application that is built as a Windows Service and a c# library assembly (.dll.) In order to manage and maintain this service, I'd like to add the ability to run a command-line application that tells the last time the service archived files, the next time it's scheduled to do so, the status of the last run, and the location of a file created by the service.
What's the best architecture for writing a service and library that can share data with another application? I'm using .net 2.0.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
.net 中进程间通信的方式是通过远程处理(即使两个进程位于同一台计算机上)。 其他回复提出了不需要远程处理的进程间通信的替代方案。
The way that inter-process communication happens in .net is through remoting (even if both processes are on the same machine). Other responses have suggested alternatives to inter-process communication which would not require remoting.
最好的架构可能是让您的服务成为一个“服务器”,可以报告其状态(以及您想要的任何信息)。 像 ocdecio 建议的那样使用 WCF 会使事情变得非常简单。
The best architecture is probably to make your service be a "server" that can report on it's status (and whatever information you want). Using WCF for this like ocdecio suggested would make it pretty simple.
我为此使用 WCF 并为我想要支持的命令/事件创建契约定义。
I use WCF for that and create a contract definition for the commands/events I want to support.
我过去应用过的选项:
(如果你手头上有一个)
“状态监视器”类型线程
客户端可以连接的服务
通过 TCP/IP 等进行访问和查询
Options that spring to mind that I've applied in the past:
(if you have one to hand)
"status monitor" type thread on the
service that the client can connect
to and query via TCP/IP etc.
一种相当简单的方法是将这些信息存储在两个应用程序都可以访问的本地配置/文本文件中。 或者甚至将其放入注册表项中。
A fairly simple approach is to store that information in either a local config / text file which both apps have access to. Or even to place it in a registry key.
+1让服务在查询时提供该数据(以及任何其他数据)(简单的tcp、RPC、Web服务或其他)
我会让它非常通用 - 就像
QueryInfo(一些标识符)
响应为某个字符串和返回值或其他指示符,表明该服务不知道您在说什么,无法获取信息或返回信息
+1 for just having the service provide that (and any other data) when it is queried (simple tcp, RPC, web service, or whatever)
I'd make it pretty generic - like
QueryInfo(some identifier)
with a response as some string and a return value or other indicator that the service does not know what you are talking about, cannot get the info, or give back the info