WCF - 最快的进程间通信
A 有一个可通过 Web 访问(通过 basicHttpBinding)的 WCF 服务,我还希望从同一台计算机上的其他 .NET 服务进行访问,并具有尽可能更高的性能。我知道 netNamedPipeBinding 非常适合此目的,但想知道如果我只与其他 .NET 进程进行通信,最好的配置是什么。
例如,我不一定需要使用诸如 SOAP 之类的编码,因为这可能太大了,而且我不需要与 .NET 客户端以外的任何其他客户端兼容。我也不认为我需要任何安全感。
为此目的的最佳绑定配置是什么(或与此相关的任何其他配置)
A have a web-accessible (via basicHttpBinding) WCF service which I also want to access from other .NET services on the same machine with as higher performance as possible. I understand that the netNamedPipeBinding is ideal for this, but wonder what the best configuration would be given that I'm only even going to be communicating with other .NET processes.
For example, I needn't necessarily use an encoding such as SOAP as this is perhaps too bulky and I don't need the compatibility with any other clients other than a .NET client. I also don't think I need any security.
What would be the best binding configuration for this purpose (or any other configurations for that matter)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
正如您所注意到的, NetNamedPipeBinding 绑定针对同机通信:
参考号: 系统提供的绑定
在 Juval Lowy 的书“编程”的第一章中WCF 服务”,他提供了一个有用的决策活动图来选择正确的绑定:
As you have noted, the NetNamedPipeBinding binding is optimised for same-machine communication:
Ref. : System-Provided Bindings
In chapter one of Juval Lowy's book, "Programming WCF Services", he provides a useful decision-activity diagram for choosing the right binding:
当然,命名管道传输是最好的选择。
默认情况下,在标准 NetNamedPipeBinding 上启用 EncryptAndSign 的传输安全性。您当然想删除它,因为这样做会加快速度而不会对安全性产生任何实际影响,原因是 我在这里讨论。
我还怀疑,但尚未证实,更改消息编码绑定元素可能会有所帮助。这是因为默认值是 WCF 专有的“带有带内字典的二进制编码”,它是 XML 信息集的编码,旨在减少冗余字节,例如在开始和结束元素标记中:当涉及网络 IO 时,这是一个有价值的目标,但当消息传输完全在内存中时(假设消息不是太大),可能会浪费 CPU 的精力。因此,更改为纯文本编码也可能会提高速度。
Certainly the Named Pipe transport is the best choice.
Transport security with EncryptAndSign is enabled by default on the standard NetNamedPipeBinding. You certainly want to remove this, as doing so will speed things up without any real impact on security, for the reasons I discuss here.
I also suspect, but have not yet confirmed, that changing the message encoding binding element may help. This is because the default is the WCF proprietary 'binary encoding with in-band dictionary', which is an encoding of an XML infoset which aims to reduce redundant bytes e.g. in opening and closing element tags: a worthy aim when network IO is involved, but maybe wasted CPU effort when message transfer is entirely in-memory (provided the messages are not too big). Thus changing to a plain text encoding might also provide a speed improvement.
我知道这是一个很老的问题,但仍然值得回答。正如已经提到的,命名管道速度最快,您需要禁用安全性,但如果您摆脱数据协定序列化并切换到基于流的传输模式,您将获得最显着的效果。
使用类似这样的内容作为绑定配置:
像这样定义您的服务消息:
此方法的缺点是现在您必须自己序列化数据。与 MemoryStream 相比,我更喜欢直接使用 protobuf 序列化。将此流放置到您的 CallRequestMessage.Parameters 中。
不要忘记在消息头中传输ParametersLen/ResultsLen,因为流是无限的(读取时您可能会收到 0 字节,但与普通流不同,您应该继续读取)。
I Understand this is a pretty old question, but it still worth answering. As already mentioned named pipes are fastest and you need to disable security, but the most dramatic effect you'll get if you get rid of data contract serialization and switch to stream-based transfer mode.
Use something like this as binding configuration:
Define your service messages like this:
The downside of this method is that now you have to serialize your data yourself. I prefer using protobuf serialization directly to MemoryStream. Place this stream to your CallRequestMessage.Parameters.
Don't forget to transfer ParametersLen/ResultsLen in the message header as Stream is endless (while reading you'll may receive 0 bytes, but unlike normal streams you should continue reading).