与 Windows 服务通信 [英] Communicating with a Windows Service

查看:35
本文介绍了与 Windows 服务通信的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找使用 Windows 服务管理一组对象的最佳方式,以供多个不同的客户端程序使用.服务必须

I'm looking for the best way to use a Windows Service to manage a group of objects for use by several different client programs. The service must

  1. 创建与物理或虚拟设备对应的对象列表,
  2. 维护有关当前正在使用给定设备的进程以及可以使用的设备的信息,
  3. 通过进程管理使用给定设备的请求,
  4. 将设备恢复到未使用状态.

但是,当我查看 Windows 服务示例时,与服务的通信非常有限.OnCustomCommand 不会向调用者返回任何信息.

When I look at the Windows Service examples, though, there is very limited communications to Services. OnCustomCommand doesn't return any information to the caller.

那么有没有推荐的方法来在服务和各种客户端之间建立信息交换?

So is there a recommended way to establish information exchange between a service and various clients?

对于背景 - 我正在用 .Net 应用程序替换 Win32/COM 应用程序.当前的设备管理器是 COM 服务器,客户端是 COM 客户端.

For background - I am replacing a Win32/COM app with a .Net app. The current device manager is a COM server with the clients being COM clients.

推荐答案

您始终可以在 Windows 服务中实现 WCF 服务以与外部世界进行通信.它将使用 HTTP 或 Net/TCP(在公司 LAN 环境中)或其他传输(如 MSMQ 消息队列,如果合适)来实现.

You could always implement a WCF service inside your Windows Service to communicate with the outside world. It would do so using either HTTP or Net/TCP (in a corporate LAN environment) or other transports (like MSMQ message queueing, if appropriate).

当 Windows 服务启动时,您还可以启动 WCF ServiceHost 来处理这些通信需求.

When the Windows Service spins up, you could also bring up a WCF ServiceHost to handle those communication needs.

见:

这篇关于与 Windows 服务通信的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆