【问题标题】:WCF Rest - mixing HTTP and HTTPS in one ServiceContractWCF Rest - 在一个 ServiceContract 中混合 HTTP 和 HTTPS
【发布时间】:2013-02-26 14:50:56
【问题描述】:

我目前有一个 Http Rest WCF4 服务,由 ServiceContract IEventService 定义,该服务仅通过 HTTP 公开。

我的任务是让 一些 OperationContracts 只能通过 HTTPS 工作,所以我将这些方法拆分为一个单独的 ServiceContract,称为 IEventServiceHTTPS

使用带有自签名证书的 IIS7.5 将它托管在我的开发机器上,作为 IEventServiceHTTPS 一部分的方法可以通过 HTTPS 而不是通过 HTTP 调用,正如预期的那样。

但是IEventService 公开的 HTTP 方法现在不起作用。

我在尝试访问 HTTP 方法时得到以下信息:

HTTP Error 403.4 - Forbidden
The page you are trying to access is secured with Secure Sockets Layer (SSL).

web.config 与我的更改:

<system.serviceModel>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" aspNetCompatibilityEnabled="true">
      <serviceActivations>
        <add service="Api.EventService" relativeAddress="EventService.svc" factory="Api.UnityServiceHostFactory"/>
      </serviceActivations>
    </serviceHostingEnvironment>
    <behaviors>
      <serviceBehaviors>
        <behavior name="Api.EventServiceBehavior">
          <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
          <serviceDebug includeExceptionDetailInFaults="true"/>
        </behavior>
      </serviceBehaviors>
      <endpointBehaviors>
        <behavior name="WebBehavior">
          <webHttp/>
        </behavior>
      </endpointBehaviors>
    </behaviors>
    <services>
      <service behaviorConfiguration="Api.EventServiceBehavior" name="Api.EventService">
        <endpoint address="" binding="webHttpBinding" behaviorConfiguration="WebBehavior" bindingConfiguration="webBindingHTTP" contract="Api.IEventService"/>
        **<endpoint address="" binding="webHttpBinding" behaviorConfiguration="WebBehavior" bindingConfiguration="webBindingHTTPS" contract="Api.IEventServiceHTTPS"/>**
      </service>
    </services>
    <bindings>
      <webHttpBinding>
        <binding name="webBindingHTTP">
          <security mode="None"></security>
        </binding>
        **<binding name="webBindingHTTPS">
          <security mode="Transport">
          </security>
        </binding>**
      </webHttpBinding>
    </bindings>
  </system.serviceModel>

任何帮助将不胜感激,谢谢。

【问题讨论】:

    标签: wcf http ssl https webhttpbinding


    【解决方案1】:

    我相信这个错误是由 IIS vdir [SSL 设置]-> 要求 SSL -> true 引起的。如果您希望在同一服务中同时访问 http 和 https 端点,请取消选中此设置,因为这将阻止您在 vdir 中执行不安全的 http。

    【讨论】:

      猜你喜欢
      • 2013-03-29
      • 1970-01-01
      • 1970-01-01
      • 2011-02-04
      • 1970-01-01
      • 2020-08-18
      • 1970-01-01
      • 1970-01-01
      • 2010-10-20
      相关资源
      最近更新 更多