C# GUI和windows服务通信

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1773046/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 20:42:08  来源:igfitidea点击:

GUI and windows service communication

c#.netuser-interfacewindows-servicescommunication

提问by Stéphane

I know since Vista, that C# can't hook a UI form directly to the windows service. This was stated on the Microsoft Site.

我知道从 Vista 开始,C# 无法将 UI 表单直接挂接到 Windows 服务。这是在 Microsoft 站点上说明的。

My question in this regard is: "What is the best mode of communication from a UI to the service?"

我在这方面的问题是:“从 UI 到服务的最佳通信模式是什么?”

I have heard of Remoting, Web services, and direct TCP. Are there other methods? How do they rank against the previously mentioned methods? How complicated are they to implement?

我听说过远程处理、Web 服务和直接 TCP。还有其他方法吗?它们与前面提到的方法相比如何?它们实施起来有多复杂?

My application is for intranet use, not internet. Microsoft platform will be on both sides, so interoperability is not a factor, but speed is. I mean I want to get across the smallest packet possible on the network.

我的应用程序是用于 Intranet 的,而不是 Internet。Microsoft 平台将在双方,所以互操作性不是一个因素,但速度是。我的意思是我想通过网络上可能的最小数据包。

TIA

TIA

采纳答案by Matt Davis

If you are going to be developing with .NET, use WCFfor your interprocess communication. WCF greatly simplifies development because the intricacies associated with a specific communication mechanism (e.g., sockets, pipes, etc.) are abstracted behind a unified programming model. Thus, it doesn't matter if you choose to use http, tcp, or named pipes for your transport mechanism, the programming model is the same.

如果您打算使用 .NET 进行开发,请使用WCF进行进程间通信。WCF 极大地简化了开发,因为与特定通信机制(例如,套接字、管道等)相关的复杂性被抽象为统一的编程模型。因此,无论您为传输机制选择使用 http、tcp 还是命名管道都没有关系,编程模型是相同的。

I would highly recommend Juval Lowy's book Programming WCF Servicesfor all things WCF. You can also visit his website, IDesign.net, for free WCF code samples.

我强烈推荐 Juval Lowy 的书Programming WCF Servicesfor all things WCF。您还可以访问他的网站IDesign.net以获取免费的 WCF 代码示例。

For an overview of WCF, watch this free videoat dnrTV. It covers the purpose of WCF and demonstrates WCF programming through some easy-to-follow examples.

有关 WCF 的概述,请在 dnrTV 上观看此免费视频。它涵盖了 WCF 的用途,并通过一些易于理解的示例演示了 WCF 编程。

If you have not already created your Windows service but plan to do so in C#, you can follow the step-by-step here.

如果您尚未创建 Windows 服务,但计划使用 C# 创建,您可以按照此处的分步说明进行操作。

回答by Remy Lebeau

There are many ways to communicate between processes - named pipes, mailslots, memory mapped files, sockets, ActiveX/COM objects, just to name a few. It really boils down to which technologies you are familiar/comfortable with.

进程间通信的方式有很多种——命名管道、邮槽、内存映射文件、套接字、ActiveX/COM 对象,仅举几例。这实际上归结为您熟悉/熟悉哪些技术。