0

我有一个 WCF (svs) Web 服务,它在 Windows 2008 IIS Web 服务器上运行。

IIS 服务器已安装 SSL 证书,并通过 HTTP 和 HTTPS 托管 Classic ASP 和 PHP。

我已经将 WCF 服务作为应用程序安装在 IIS 服务器上(在同一个域上),它可以完美地使用 HTTP 和 HTTPS 服务请求。

但是,我希望这个 WCF 服务只提供 HTTPS 请求和响应。

为了实现这一点,我需要在 WCF web.config 中进行哪些更改?

更新

继我上面的帖子之后,我设法研究了以下似乎可以使用 web.config 文件工作的内容;

<system.serviceModel>
    <services>
     <service behaviorConfiguration="returnFaults" name="MyService.MonitorService">
      <endpoint binding="wsHttpBinding" bindingConfiguration=
            "TransportSecurity" contract="MyService.IMonitorSvc" />
     </service>
   </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="returnFaults">
          <!-- To avoid disclosing metadata information, set the values below to false before deployment -->
          <serviceMetadata httpGetEnabled="true" httpsGetEnabled="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>
    </behaviors>
    <bindings>
        <wsHttpBinding>
           <binding name="TransportSecurity">
                 <security mode="Transport">
                  <transport clientCredentialType="None"/>
                  </security>
            </binding>
          </wsHttpBinding>
    </bindings>
    <protocolMapping>
        <add binding="basicHttpsBinding" scheme="https" />
    </protocolMapping>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
  </system.serviceModel>

谁能确认这是 WCF 服务的正确方法,强制所有请求都通过 HTTPS (SSL) 发出?

基本上使用上述内容,用户是否能够向服务发出 HTTP 请求?或者该服务是否总是强制执行 HTTPS

感谢您的澄清。

4

1 回答 1

2

使用Microsoft URL Rewrite 模块,然后将以下内容添加到您的 web.config 文件中:

<system.webServer>
    <rewrite>
        <rules>
            <clear />
            <rule name="Redirect to https" stopProcessing="true">
                <match url="(.*)" />
                <conditions>
                    <add input="{HTTPS}" pattern="off" ignoreCase="true" />
                </conditions>
                <action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" redirectType="Permanent" />
            </rule>
        </rules>
    </rewrite>
</system.webServer>

如果这是不可接受的(因为您必须记住在其他部署中添加此模块),那么这个答案指出了如何编写自己的 https 重定向器。

我对此并不完全确定,但您也可以使用它System.Web.HttpContext.Current.Request.IsSecureConnection来检查您的实际代码。

于 2013-10-09T16:56:46.970 回答