WCF NetTCPBinding vs HttpBinding difference in data sent on wire

冷暖自知 提交于 2019-12-06 03:37:37

问题


Say I have a service exposing two end points, 1st is a NetTCPBinding the second is any flavour of HttpBinding. They both implement exactly the same service contract.

What is the difference in what is sent on the wire?

  • Using netTcp is my message still serialised to XML ? Or some binary representation of my objects?
  • In terms of what receives the messages what is the difference? Will the http endpoint only understand http commands (get/post etc) where as the nettcp end point understands something different?
  • Why is nettcp more efficient (in this case I dont need interoperability) than http - where is the overhead?

I think that in all cases, before the message is put onto the wire it will be converted to binary so, also http sits on top of tcp in networking terms - so somewhere extra is needed for http communications.

Appreciate the question is a bit vague but hopefully someone will know what I am trying to ask :)


回答1:


In WCF a particular binding does not necessarily imply a particular encoding. Various bindings can be configured to use various encodings. Net.TCP uses a binary encoding by default (MTOM I think), and HTTP uses a text/xml encoding by default.

With net.tcp your messages go sender -> net.tcp -> receiver. With HTTP they go from sender -> http -> tcp -> http -> receiver. There's an extra layer. The advantage of tcp is both of those: Both the extra layer and the default encoding.

HTTP with a binary encoding approaches net.tcp performance.

EDIT: Actually I think there may also be other optimizations in Net.TCP. It's a WCF-WCF communication scenario, so MS has control of both ends.



来源:https://stackoverflow.com/questions/5500030/wcf-nettcpbinding-vs-httpbinding-difference-in-data-sent-on-wire

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