C# .NET 进程间通信的最佳选择是什么?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/84855/
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
What is the best choice for .NET inter-process communication?
提问by mrbradleyt
Should I use Named Pipes, or .NET Remoting to communicate with a running process on my machine?
我应该使用命名管道还是 .NET Remoting 与我机器上正在运行的进程进行通信?
采纳答案by Eric Schoonover
WCF is the best choice. It supports a number of different transport mechanisms(includingNamedPipes) and can be completely configuration driven. I would highly recommend that you take a look at WCF.
WCF是最好的选择。它支持许多不同的传输机制(包括命名管道)并且可以完全由配置驱动。我强烈建议您查看 WCF。
Here is a blog that does a WCF vs Remoting performance comparison.
这是一个进行WCF 与 Remoting 性能比较的博客。
A quote from the blog:
引自博客:
The WCF and .NET Remoting are really comparable in performance. The differences are so small (measuring client latency) that it does not matter which one is a bit faster. WCF though has much better server throughput than .NET Remoting. If I would start completely new project I would chose the WCF. Anyway the WCF does much more than Remoting and for all those features I love it.
WCF 和 .NET Remoting 在性能上确实相当。差异是如此之小(测量客户端延迟),以至于哪个更快一点都无关紧要。WCF 虽然比 .NET Remoting 有更好的服务器吞吐量。如果我要开始一个全新的项目,我会选择 WCF。无论如何,WCF 的功能远不止 Remoting,而且我喜欢它的所有这些功能。
回答by kemiller2002
.net remoting is built into .net to do inner process communication. If you use that, they will continue to support and possibly enhance it in future versions. Named pipes doesn't give you the promise of enhancements in future versions of .net
.net 远程处理内置于 .net 中以进行内部进程通信。如果您使用它,他们将继续支持并可能在未来版本中增强它。命名管道并没有承诺在 .net 的未来版本中进行增强
回答by Dario Solera
If you mean inter-process communication, I used .NET Remoting without any problem so far. If the two processes are on the same machine, the communication is quite fast.
如果您的意思是进程间通信,那么到目前为止我使用 .NET Remoting 没有任何问题。如果这两个进程在同一台机器上,那么通信是相当快的。
Named Pipes are definitely more efficient, but they require the design of at least a basic application protocol, which might not be feasible. Remoting allows you to invoke remote methods with ease .
命名管道肯定更有效,但它们至少需要设计一个基本的应用程序协议,这可能不可行。远程处理允许您轻松调用远程方法。
回答by Mark Cidade
If it's on a single machine, Named Pipes gives you better performance and can be implemented with the remoting infrastructureas well as WCF. Or you can just directly use System.IO.Pipes.
如果它在单台机器上,命名管道可为您提供更好的性能,并且可以使用远程处理基础设施和 WCF来实现。或者你可以直接使用System.IO.Pipes。
回答by Joel Coehoorn
.Net remoting isn't a protocol in and of itself. It lets you pick which protocal to use: SOAP, named-pipes, etc.
.Net 远程处理本身并不是一种协议。它允许您选择要使用的协议:SOAP、命名管道等。
回答by icelava
Remoting in .NET Framework 2.0 provides the IPC channelfor inter-process communication within the same machine.
.NET Framework 2.0 中的远程处理为同一台机器内的进程间通信提供了IPC 通道。
回答by Jason Olson
If you are using the .NET Framework 3.0 or above, I would use WCF. Using WCF, you can use different bindings depeneding on the trade-off between performance/interop/etc. that you need.
如果您使用 .NET Framework 3.0 或更高版本,我会使用 WCF。使用 WCF,您可以根据性能/互操作/等之间的权衡使用不同的绑定。你需要的。
If performance isn't critical and you need interop with other Web Service technologies, you will want to use the WS-HTTP binding. For your case, you can use WCF with either a net-tcp binding, or a named-pipe binding. Either should work.
如果性能不是很重要,并且您需要与其他 Web 服务技术进行互操作,那么您将需要使用 WS-HTTP 绑定。对于您的情况,您可以将 WCF 与 net-tcp 绑定或命名管道绑定一起使用。要么应该工作。
My personal take is that the WCF approach is more clean as you can do Contract-Driven services and focus on messages, not objects (I'm making a generalization here based on the default programming models of WCF/.NET Remoting). I don't like sending objects across the wire because a lot of semantic information gets lost or is not clear. When all you are doing is sending a message like you are with WCF, it becomes easier to separate your concerns between communication and the classes/infrastructure that a single node is composed of.
我个人认为 WCF 方法更简洁,因为您可以执行契约驱动的服务并专注于消息,而不是对象(我在此基于 WCF/.NET Remoting 的默认编程模型进行概括)。我不喜欢通过网络发送对象,因为很多语义信息会丢失或不清楚。当您所做的只是像使用 WCF 一样发送消息时,就可以更轻松地将您的关注点在通信与组成单个节点的类/基础设施之间分开。
回答by Vikram I Code
WCF also provides flexibility. By just changing some config (binding) you can have the same service on some other machine instead of IPC on same machine. Therefore your code remains flexible.
WCF 还提供了灵活性。只需更改一些配置(绑定),您就可以在其他机器上使用相同的服务,而不是在同一台机器上使用 IPC。因此,您的代码保持灵活。