在启用 SSL 的情况下将 WCF 服务移动到 IIS6

Moving WCF service to IIS6 with SSL enabled

我在未启用 SSL 的服务器上 运行 我的 WCF 服务,现在我将其移至启用了 SSL 的服务器上,但出现以下错误:

Could not find a base address that matches scheme http for the endpoint with binding BasicHttpBinding. Registered base address schemes are [https].

以下是我的设置:

<bindings>
  <basicHttpBinding>
    <binding name="basicHTTP">
      <security mode="TransportCredentialOnly">
        <transport clientCredentialType="Windows">
        </transport>
      </security>
    </binding>
  </basicHttpBinding>
</bindings>
<services>
  <service behaviorConfiguration="basicBehavior" name="ProjectName.MyService">
    <endpoint address="" binding="basicHttpBinding" bindingConfiguration="basicHTTP" contract="ProjectName.IMyService"/>
  </service>
</services>
<behaviors>
  <serviceBehaviors>
    <behavior name="basicBehavior">
      <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
      <serviceDebug includeExceptionDetailInFaults="true"/>
    </behavior>
  </serviceBehaviors>
</behaviors>

我该如何解决这个错误?

您需要为 basicHttps 定义绑定。这是适用于 SSL 的非常简单的设置:

<system.serviceModel>
    <bindings>
      <basicHttpsBinding>
        <binding name="BasicHttpBinding_IMyService" />
      </basicHttpsBinding>
    </bindings>

    <client>
      <endpoint
        name="BasicHttpBinding_IMyService"
        address="https://MyURL/MyService.svc/soap/"
        binding="basicHttpsBinding"
        bindingConfiguration="BasicHttpBinding_IMyService"
        contract="ClientServiceReference.IMyService" />
    </client>

  </system.serviceModel>

注意:需要定义端点,其URL为https.

此外,请确保在生产环境中,您没有将异常详细信息发送回调用方(这将被视为系统中的安全漏洞,因为异常可能会向黑客泄露太多信息)。您必须更改此行:

<serviceDebug includeExceptionDetailInFaults="false"/>

通过将安全模式指定为 Transport 并使用 webHttpBinding

解决了该问题