Communicating with a Windows Service

依然范特西╮ 提交于 2019-12-10 06:25:24

问题


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. create the list of objects corresponding to physical or virtual devices,
  2. maintain information about what process is currently using a given device and what devices are available to be used,
  3. manage requests to use a given device by a process,
  4. return devices to an unused state.

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?

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.


回答1:


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).

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

See:

  • MSDN: How to host a WCF service in managed Windows Service
  • Self-hosting WCF services
  • WCF Essentials - hosting the service



回答2:


Just an option - MsgConnect library for transparent communications between applications on the same or different systems. Designed specifically with your task (service-GUI communication) in mind. With MsgConnect you can send and receive messages (much like you do in Windows) which carry custom data. On local system messages can be transferred using MMF or sockets, for remote communications TCP sockets or HTTP can be used.



来源:https://stackoverflow.com/questions/3294502/communicating-with-a-windows-service

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!