简体   繁体   English

我应该使用 WCF 来实现给定的二进制网络协议吗?

[英]Should I use WCF to implement a given binary network protocol?

I have a client device (POS handheld) which communicates via TCP/IP or RS232 with it's server.我有一个客户端设备(POS 手持设备),它通过 TCP/IP 或 RS232 与其服务器进行通信。 The protocol is a given binary format, which I cannot change.该协议是给定的二进制格式,我无法更改。 I have to implement a server for that device.我必须为该设备实现一个服务器。 My impression is, that WCF would be a better choice than implementing anything by hand.我的印象是,WCF 将是比手动实现任何东西更好的选择。 But because it would require quite some time to give it a try, I would like to ask for advice whether it's a good idea and if it's possible to fine tune WCF to such a level of detail.但是因为尝试它需要相当长的时间,所以我想请教一下这是否是一个好主意,以及是否可以将 WCF 微调到如此详细的水平。

I found some questions which are similar to mine, but in those cases the OP had always full control over client and server.我发现了一些与我的问题相似的问题,但在这些情况下,OP 始终完全控制客户端和服务器。 That's not the case for my scenario.我的情况并非如此。

If WCF is a good idea - which I assume - some starting points would be very appreciated.如果 WCF 是一个好主意 - 我假设 - 一些起点将不胜感激。 Most documentation focus on SOAP, REST, ... and not on the lower levels I would have to work on.大多数文档都集中在 SOAP、REST ……而不是我必须处理的较低级别。

Having worked with WCF for many years (and liking it), I don't think it's the best option for your needs.与 WCF 合作多年(并且喜欢它),我认为它不是满足您需求的最佳选择。 As Phil mentioned, it's sweet spot is around web services, not low level communication.正如菲尔所提到的,它的最佳点是围绕 web 服务,而不是低级别的通信。 To implement that in WCF, you'd need to write a custom transport, which, as with almost all of the low-level (channel programming), involves a lot of code.要在 WCF 中实现这一点,您需要编写一个自定义传输,与几乎所有低级(通道编程)一样,它涉及大量代码。 This transport would need to use sockets to understand the device protocol, and you'd need to somehow convert the messages from the protocol into WCF messages.此传输需要使用 sockets 来理解设备协议,并且您需要以某种方式将协议中的消息转换为 WCF 消息。

If the protocol is simple, I think that a "pure" socket based implementation would be the best way to go.如果协议很简单,我认为基于“纯”套接字的实现将是 go 的最佳方式。 The socket handling code (to communicate with the device) would be needed in a WCF solution anyway, but you can create your own message types instead of having to conform to a (rather SOAP-friendly) message protocol used by WCF.无论如何,在 WCF 解决方案中都需要套接字处理代码(与设备通信),但您可以创建自己的消息类型,而不必遵守 WCF 使用的(相当 SOAP 友好的)消息协议。

One advantage that you'd have if you were to go all the way and implement the custom WCF transport which "talks" that protocol would be if you were to expose it to many different people who are already used to a WCF-way of implementing services - you'd have to bear the initial (very high) cost of writing a WCF transport, but later on people can write services for that device using the nice contract model that WCF provides.如果您一直使用 go 并实现自定义 WCF 传输,那么您将拥有的一个优势,如果您要将它公开给已经习惯于 WCF 实现方式的许多不同的人,该协议将“谈论”该协议服务 - 您必须承担编写 WCF 传输的初始(非常高)成本,但后来人们可以使用 ZFB608636129CB469B7FE911E92E2B56 提供的良好合同 model 为该设备编写服务。

WCF has quite a learning curve as is, and if you need to be customizing lots of very low-level things, the curve will be steeper. WCF 有相当长的学习曲线,如果你需要定制很多非常低级的东西,曲线会更陡峭。

Also, the reason WCF was created was to allow the developer to not worry about lower level implementation details.此外,创建 WCF 的原因是让开发人员不必担心较低级别的实现细节。 It seems like you want the best of both worlds, which means you will probably be spending most of your time fighting WCF to get it to work how you want.似乎您想要两全其美,这意味着您可能会花费大部分时间与 WCF 战斗以使其按您的意愿工作。

Disclaimer: While I have a basic understanding of WCF, I am not an expert and I could be wrong.免责声明:虽然我对 WCF 有基本的了解,但我不是专家,我可能是错的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM