基本的Http绑定 vs WsHttp绑定 vs WebHttp绑定

318
在WCF中,有几种不同类型的基于HTTP的绑定:

这三者之间有哪些区别?

特别是在功能、性能和兼容性方面有何不同?


49
基本Http绑定 = Soap 1.1,WsHttp绑定 = Soap 1.2,WebHttp绑定 = Rest。 - Frank Myat Thu
这里对两种基于SOAP的绑定进行了比较:basicHttpBinding vs wsHttpBinding - DavidRR
3个回答

541

这里你在比较不同的东西:

  • webHttpBinding 是REST风格的绑定,基本上您只需访问一个URL并从Web服务获得大量的XML或JSON数据即可

  • basicHttpBindingwsHttpBinding 是两种基于SOAP的绑定,与REST非常不同。 SOAP的优点是具有WSDL和XSD来详细描述服务、其方法和传递的数据(REST没有类似的东西 - 尚未)。 另一方面,您不能仅使用浏览器浏览到wsHttpBinding端点并查看XML - 您必须使用SOAP客户端,例如WcfTestClient或您自己的应用程序。

因此,您的第一个决定必须是:REST vs. SOAP(或者您可以从服务中公开这两种类型的端点 - 这也是可能的)。

然后,在basicHttpBinding和wsHttpBinding之间,它们的区别如下:

  • basicHttpBinding是非常基本的绑定 - SOAP 1.1,安全性不高,功能方面也不多 - 但与任何SOAP客户端兼容-->非常适合互操作性,但在功能和安全性上比较弱

  • wsHttpBinding是全功能绑定,支持大量的WS-*功能和标准 - 它具有更多的安全功能,您可以使用会话连接,您可以使用可靠性消息传输,您可以使用事务控制-只有更多的东西,但wsHttpBinding也非常“重”,并且在消息在网络上传输时会增加很多开销

要进行深入比较(包括表格和代码示例),请查看此CodeProject文章:Differences between BasicHttpBinding and WsHttpBinding


1
亲爱的,我这里并没有做出任何决定,我只是想知道区别。你必须知道橙子和苹果的味道不同,这就是为什么我问这个问题。我需要更多关于WebHttpBinding的特性比较和性能方面的信息。 - Mubashar
4
一个更正:wsHttpBinding不支持流式传输。或者我有什么遗漏吗?http://msdn.microsoft.com/en-us/library/ms730879.aspx - Andrew Shepherd
1
@Andrew Shepherd:感谢你提供的链接和更正 - 你是完全正确的,wsHttpBinding不支持流式传输..... - marc_s
如果他们将其命名为restHttpBinding而不是webHttpBinding,那么这样做是否有问题?那会更加具有信息性。 - Jim Aho
@JimAho:命名很难 - 这是计算机科学中的两个经典问题之一(除了缓存失效)... - marc_s
显示剩余3条评论

0
如果在将文件复制到 Web 服务器时出现缺少服务命名空间引用的情况,请尝试以下方法。我们发现,发布项目并将 App_WebReference.dll 文件复制到 bin 文件夹中可以解决该问题。然后,可以将从将服务添加到项目中生成的绑定复制到 web.config 中,以便将其复制到服务器的 web.config 中。

0
It will depend on the usage and when the specific binding can be chosen
BasicHttpBinding -->Use this when you need very minimal security and reliability and the need is to extend the legacy classic ones and get them migrated to the new WCF world without much hassle.
WsHttpBinding-->Use this when you want message and transport level security along with reliability. Along with this it also has dual transactions and all option in case we need duplex level of work in project
WebHttpBinding-->Use this when the need is only on HTTP protocol and it will be using Verbs like Get, Put , Post , Delete and  just like Asp.Net WebAPI usage we need to use this type of binding.

Hope this helps.

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接