【问题标题】:Enabling http and https on the same service在同一服务上启用 http 和 https
【发布时间】:2014-10-17 06:21:31
【问题描述】:

我正在编写一个包含单一合同的 WCF 服务。我希望 Web 客户端使用 http 或 https 调用服务端点。

我的web.config如下:

(为简洁起见,已删除某些部分)

<system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding name="BasicHttpBinding_IDataService" />
        <binding name="BasicHttpsBinding_IDataService" >
          <security mode="Transport" />
        </binding>
      </basicHttpBinding>
    </bindings>

    <services>
      <service behaviorConfiguration="DataServiceMetadataBehavior" name="DummyService.DataService">

        <endpoint address="" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IDataService"
          contract="DummyService.IDataService"/>

        <endpoint address=""
                 binding="basicHttpBinding" bindingConfiguration="BasicHttpsBinding_IDataService"
                 contract="DummyService.IDataService" name="BasicHttpsBinding_IDataService" 
                  />

      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="DataServiceMetadataBehavior">
          <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
          <serviceDebug includeExceptionDetailInFaults="false"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <protocolMapping>
      <add scheme="http" binding="basicHttpBinding" />
      <add scheme="https" binding="basicHttpBinding" />

    </protocolMapping>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true"/>
  </system.serviceModel>

当我尝试使用 VisualStudio 测试客户端测试服务时,出现以下错误:

找不到与方案 https 匹配的基地址 具有绑定 BasicHttpBinding 的端点。注册基址 方案是 [http]。

只有一个端点,一切正常。

【问题讨论】:

    标签: c# wcf soap


    【解决方案1】:

    端点由地址、绑定和合约组成。 http://YourBaseAddress/YourApp/YourService.svchttpS://YourBaseAddress/YourApp/YourService.svc 是不同的地址,具有不同的架构名称或协议以及不同的端口:默认情况下为 80 和 443,因此您可以拥有服务的两个端点,具有相同的 basicHttpBinding,前提是 https 有一个正如您所做的那样用于 SSL 传输的 bindingConfiguration。该错误消息信息量很大,因此您需要转到 IIS(或 IIS Express)以确保有一个 http 侦听器,例如在检查网站的“编辑绑定”功能后定义的 https 绑定。完成此操作后,您应该可以在 Web 浏览器中通过httpS://YourBaseAddress/YourApp/YourService.svc?wsdl 获取 WSDL。

    事实上,许多 Web 服务/应用程序(例如 Microsoft 和 Google 的 Web 服务/应用程序)通过相同的主机名和路径同时支持 http 和 https。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-25
      • 2020-12-15
      • 1970-01-01
      • 2020-12-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多