【问题标题】:WebHttpBinding not reaching the clientWebHttpBinding 未到达客户端
【发布时间】:2011-06-11 12:28:23
【问题描述】:

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

当我进行服务引用时,我只获得了创建了 basicHttpBinding 和 wsHttpBinding 绑定的端点。我没有得到 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>

【问题讨论】:

    标签: wcf wcf-binding webhttpbinding


    【解决方案1】:

    没有任何问题 - 这就是它的工作方式!

    basicHttpBindingwsHttpBinding 是 SOAP 绑定,它们公开有关其服务的元数据 - 您的 Visual Studio Add Service Reference 可以询问它们的端点,找出它们的名称、它们提供的方法、它们期望的数据类型参数以及它们返回的内容。

    webHttpBinding 是 REST - 默认情况下 REST 没有元数据的概念 - 你不会得到服务描述、方法列表等 - REST 就是关于资源 -不是方法。

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

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

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

    【讨论】:

    • 谢谢@marc_s,我同意你的回答。但我想通过创建客户端来体验 webHttpBinding。通俗地说,我应该怎么做才能在 Visual Studio 中创建此服务的代理并开始使用它?
    • @SaravananArumugam:正如我试图解释的那样:使用“正常”的 webHttpBinding,您无法获得客户端代理 - 根本没有这样的东西。如果您想要一个基于 REST 的服务的客户端代理,您需要创建一个 WCF 数据服务(参见此处:lhotka.net/weblog/CSLA4Version41Release.aspx
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-07-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-05-03
    • 1970-01-01
    相关资源
    最近更新 更多