wcf - WebHttpBinding 未到达客户端

标签 wcf wcf-binding webhttpbinding

我创建了一个 Web 服务,我试图为其提供 3 个具有不同绑定(bind)的端点。
1.基本的HttpBinding,
2.wsHttpBinding,
3.webHttpBinding

当我进行服务引用时,我只获得了创建了 basicHttpBinding 和 wsHttpBinding 绑定(bind)的端点。我没有得到 webHttpBinding。什么可能是错的。

这是 web.config 中 serviceModel 节点的结构。

  <system.serviceModel>
<diagnostics>
  <messageLogging logEntireMessage="true" logMessagesAtServiceLevel="true" logMessagesAtTransportLevel="true"/>
</diagnostics>
<services>
  <service behaviorConfiguration="VersionTolerance.Service1Behavior" name="BookShop.BookShopService">
    <endpoint address="sadha" binding="basicHttpBinding" contract="BookShop.IBookShopService" />
    <endpoint address="ws" binding="wsHttpBinding" contract="BookShop.IBookShopService" >
    </endpoint>
    <endpoint address="web" binding="webHttpBinding" behaviorConfiguration="webHttpBehavior"
      contract="BookShop.IBookShopService" />
    <host>
      <baseAddresses>
        <add baseAddress="http://localhost:49654/" />
      </baseAddresses>
    </host>
  </service>
</services>
<behaviors>
  <serviceBehaviors>
    <behavior name="VersionTolerance.Service1Behavior">
      <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
      <serviceMetadata httpGetEnabled="true"/>
      <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
      <serviceDebug includeExceptionDetailInFaults="false"/>          
    </behavior>
  </serviceBehaviors>
  <endpointBehaviors>
    <behavior name="webHttpBehavior">
      <webHttp/>
    </behavior>
  </endpointBehaviors>
</behaviors>

最佳答案

没有错 - 这就是它的工作方式!
basicHttpBindingwsHttpBinding是公开有关其服务的元数据的 SOAP 绑定(bind) - 您的 Visual Studio Add Service Reference可以询问它们的端点,找出它们的名称、它们提供的方法、它们期望作为参数的数据类型以及它们返回的内容。
webHttpBinding是 REST - 默认情况下 REST 没有元数据的概念 - 你不会得到服务描述、方法列表等 - REST 完全是关于 资源 - 不是方法。

因此,当您执行 Add Service Reference ,您将获得 SOAP 端点的代理客户端 - 但是 不是 对于 REST/webHttpBinding端点。按设计工作。

WCF 数据服务 - 建立在 REST 之上 - 提供与 SOAP 绑定(bind)类似的体验,您可以执行 Add Service Reference并获得一个不错的客户端代理等等——这是因为 OData 协议(protocol)在 REST 之上定义了元数据交换。因此,如果您可以将 REST 服务转变为 WCF 数据服务,那么您就可以了。

否则,使用 REST,您只需“知道”(从文档页面或其他内容)您的 REST 服务的资源 URI 是什么,以及 HTTP 动词在您的 REST 上下文中的作用。

关于wcf - WebHttpBinding 未到达客户端,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4731548/

相关文章:

c# - 如何使用 basicHttpBinding(SOAP,而非 REST)启用 Wcf 帮助页面

c# - WCF 显示来自 DataMember 的 DisplayAttribute 或 DisplayName

WCF Web Api 与 WebHttpBinding

wcf - WebHttpBinding 安全问题

.net - 在 silverlight 上异步调用同步 WCF 操作协定方法

c# - ASP.NET WebApi SelfHost 服务在 HTTP URL 注册时失败

c# - 是否可以使用 C# WCF WebHttpBinding 创建 session (如 php session )?

wcf - 从另一个 WCF 服务调用时要考虑的事项

c# - WCF 托管问题

具有基本身份验证的基于 WCF SSL Rest 的 Web 服务