4

我创建了一个 Web 服务,我试图为其提供 3 个具有不同绑定的端点。1.basicHttpBinding,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>

4

1 回答 1

10

没有错 - 这就是它的工作方式!

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

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

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

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

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

于 2011-01-19T05:59:44.410 回答