WCF是建立在套接字上的吗? [英] Is WCF built on sockets?

查看:107
本文介绍了WCF是建立在套接字上的吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试更详细地了解使用套接字进行编程,而不仅仅是使用API​​调用。我对使用C ++中的WinSocks进行C#WCF和套接字编程有相当的了解。现在我有两个主要问题:

I am trying to understand programming with sockets on a more detailed level rather than just with the API callings. I have fair understanding of C# WCF and socket programming using WinSocks in C++. Now I have 2 main questions:


  1. 在所有情况下,WCF是否都在内部使用套接字进行通信。换句话说,WCF是套接字周围的包装器吗?

  2. 所有基于网络的通信是否都在最后使用套接字来发送/接收数据,而这正是WCF所要求的。 OSI模型?

稍微详细的解释将比仅是/否答案更好。

A little detailed explanation will be better than just a Yes/No answer.

推荐答案

(向同意重新打开此问题的其他SO用户致谢)。

(With acknowledgement to the other SO users who agreed to reopen this question).

请注意,请记住这是 2019 2020年,并且 WCF已过时,我个人很高兴看到它消失了,我强烈建议不要将WCF用于任何新项目,我建议人们会尽快从WCF过渡。

As an opening remark, remember that it's 2019 2020 and WCF is obsolete and I'm personally glad to see it gone, and I strongly recommend against using WCF for any new projects and I advise people to transition away from WCF as soon as possible.

现在,针对您的问题(我的粗体强调):

Now, in response to your question (bold emphasis mine):


WCF是否在内部使用套接字进行通信在所有情况下。换句话说,WCF是套接字周围的包装器吗?

Does WCF use sockets internally for the communication in all cases. In other words is WCF a wrapper around sockets and is built upon them?

WCF是一个与消息处理有关的.NET平台。 WCF试图抽象出消息传输的底层细节(但是它是如此可怕,所以今天没人应该使用它),因此完全有可能构建一个实现以下目的的WCF应用程序:机器和网络之间的通信,而无需使用Windows的Winsock或任何给定计算平台提供的套接字式API。

WCF is a .NET platform that is concerned with "message processing". WCF tries to abstract away the underlying details of message transport (but it does so horribly, and so no-one should use it today), so it is entirely possible to build a WCF application that achieves inter-machine and inter-network communication without ever using Windows' Winsock, or whatever "Socket"-esque API is available for a given computing platform.

现在,表面上看WCF是所有关于抽象的知识,实际上WCF都是围绕SOAP消息而设计的(SOAP也很可怕,但这是另一个讨论),SOAP主要使用HTTP作为消息传输-HTTP主要使用TCP / IP,几乎每个单独的TCP / IP Microsoft Windows上的应用程序将在进程的通信堆栈中的某个位置使用Winsock API。 (可以争论的是,Windows上的HTTP应用程序将使用 http.sys ,它在内核模式下执行HTTP请求/响应处理,这是必要的表示绕过Windows用户模式的Winsock API,而 http.sys 使用 Winsock内核是它自己的东西)。

Now, while ostensibly WCF is all about abstraction, in practice WCF was geared around SOAP messages (and SOAP is horrible too, but that's another discussion), and SOAP primarily uses HTTP as a message transport - and HTTP primarily uses TCP/IP, and almost every single TCP/IP application on Microsoft Windows will be using the Winsock API somewhere in the process' communication stack. (It can be argued that HTTP applications on Windows will use http.sys which performs HTTP request/response processing in kernel-mode, which necessarily means bypassing Windows' user-mode Winsock API and instead http.sys uses "Winsock Kernel" which is its own thing).

在上一段中,请注意使用主要一词(而不是排他地或始终)-因为:

In the above paragraph, note the use of the word "primarily" (as opposed to "exclusively" or "always") - because:


  • WCF不必使用SOAP,它可以使用其他消息传递模型/协议/范例,例如 net.tcp (它本身更像是二进制文件 SOAP)或什至是REST(尽管REST支持在WCF的生命周期中来得很晚,而配置正确的SOAP完全是痛苦的

  • SOAP不必使用HTTP,它可以使用其他传输方式,例如SMTP。 WCF明确支持其他SOAP其他主要传输方式,例如SMTP和FTP

  • 虽然HTTP有效地绑定到了TCP / IP,而Winsock是用户模式应用程序使用TCP / IP的唯一真实方式,

  • 当然,在所有这些过程中,用户都不需要使用TCP / IP(至少,不是您想的那样-请参阅我的脚注)。

  • 模式应用程序始终可以自由使用Winsock或BSD套接字以外的其他网络编程接口(例如,Windows的命名管道提供了流式IPC接口,就像TCP的行为一样-或网络接口卡的供应商可能拥有它自己的专有网络API,在某种程度上比Sockets API更好(类似于1990年代中期的GPU供应商如何推销自己的API(Glide,PowerVR,Rendition等),直到他们都发现必须支持Direct3D和OpenGL(谁使用Metal?

  • 虽然WCF并不是在设计时就考虑到了可测试性,但仍然可以在集成测试环境中托管和运行WCF应用程序,而实际的消息传输只是

  • WCF doesn't have to use SOAP, it can use other messaging models/protocols/paradigms like net.tcp (which itself is more like a "binary SOAP") or even REST (though REST support came late in WCF's lifespan and it's a total pain to configure correctly, YMMV).
  • SOAP doesn't have to use HTTP, it can use other transports like SMTP. And WCF expressly supports other SOAP's other main transports like SMTP and FTP.
  • While HTTP is effectively tied to TCP/IP and Winsock is the only real way a user-mode application will use TCP/IP, other transports like SMTP don't have to use TCP/IP (at least, not in the way you think - see my footnote).
  • And of course, throughout all of this - user-mode applications are always free to use a different Networking Programming Interface besides Winsock or BSD sockets (for example, Windows' named-pipes present a streaming IPC interface just like how TCP behaves - or the vendor of a network-interface-card could have its own exclusively networking API which is somehow simply better than the Sockets API (similar to how GPU vendors in the mid-1990s were pushing their own APIs (Glide, PowerVR, Rendition, etc) until they all ended-up having to support Direct3D and OpenGL (and who uses Metal? hah).
  • And while WCF isn't exactly designed with testability in mind, it is still possible to host and run WCF applications inside an integration-testing environment where the actual message transport is just a thin proxy, fake, or mock object.

但是在实践中-在Win32中,联网是使用Winsock完成的-这是Microsoft的实现BSD套接字API的功能-因此,如果您使用WCF在机器之间进行通信,那么我可以99%的确定地说,最终您的消息将通过Winsock。

But in practice - in Win32, networking is accomplished using Winsock - which is Microsoft's implementation of the BSD Sockets API - so if you're using WCF to communicate between machines then I can say with 99% certainty that eventually your messages will pass-through Winsock.

脚注::关于在不使用套接字的情况下将WCF与SMTP一起使用:许多SMTP电子邮件服务器(包括Microsoft Exchange Server)都支持 提取目录-由电子邮件服务器主动监视的文件系统目录,它检测何时将新文件添加到该文件夹​​并以n SMTP信封,并以与服务器SMTP服务端点接收的SMTP信封相同的方式进行处理-如果要将SOAP-in-SMTP消息丢弃到拾取目录中,并且发往本地的接收者到提取目录的电子邮件服务,那么该消息也将完全不会通过Winsock。

Footnote: Regarding using WCF with SMTP without using Sockets: Many SMTP e-mail servers, including Microsoft Exchange Server, support "pickup directories" - which are filesystem directories actively monitored by the e-mail server, which detects when a new file has been added to the folder and reads each file as an SMTP envelope and processes it the same way as though it was an SMTP envelope received by the server's SMTP service endpoint - if a SOAP-in-SMTP message were to be "dropped" inside the pickup directory and it was destined for a recipient local to the pickup directory's e-mail service, then that message will not pass through Winsock at all either.

这篇关于WCF是建立在套接字上的吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆