如何在IIS中仅使用WCF进行basichttpbinding,SSL和基本身份验证?

时间:2010-05-25 13:09:34

标签: wcf ssl wcf-binding wcf-security basichttpbinding

是否可以仅使用BasicHttpBinding-binding在IIS中使用SSL和基本身份验证设置WCF服务? (我不能使用wsHttpBinding-binding)

该站点托管在IIS 7上,并设置了以下身份验证:

   - Anonymous access: off
   - Basic authentication: on
   - Integrated Windows authentication: off !!

服务配置:

<services>
  <service name="NameSpace.SomeService">
    <host>
      <baseAddresses>
        <add baseAddress="https://hostname/SomeService/" />
      </baseAddresses>

    </host>
    <!-- Service Endpoints -->
    <endpoint address="" binding="basicHttpBinding"
              bindingNamespace="http://hostname/SomeMethodName/1"
              contract="NameSpace.ISomeInterfaceService"
              name="Default"
                      />
    <endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange"/>
  </service>
</services>
<behaviors>
  <serviceBehaviors>
    <behavior>
      <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
      <serviceMetadata 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"/>
      <exceptionShielding/>
    </behavior>
  </serviceBehaviors>
</behaviors>

我尝试了两种具有两种不同错误的绑定:

1 - IIS错误:'无法找到与绑定BasicHttpBinding的端点的方案http匹配的基址。注册的基地址方案是[https]。

<bindings>
  <basicHttpBinding>
    <binding>
      <security mode="TransportCredentialOnly">
        <transport clientCredentialType="Basic"/>
      </security>
    </binding>
  </basicHttpBinding>

</bindings>

2 - IIS错误:此服务的安全设置需要“匿名”身份验证,但未为承载此服务的IIS应用程序启用。

<bindings>
  <basicHttpBinding>
    <binding>
      <security mode="Transport">
        <transport clientCredentialType="Basic"/>
      </security>
    </binding>
  </basicHttpBinding>

</bindings>

有人知道如何正确配置吗? (如果可能的话?)

1 个答案:

答案 0 :(得分:24)

经过一些挖掘并向几位同事提问后,我们终于解决了这个问题。

重要的是要了解在这种情况下安全性有两个方面。 IIS安全性和WCF安全性。

IIS安全性:启用SSL&amp;启用基本身份验证禁用匿名身份验证。 (当然,创建一个Windows帐户/组并在IIS中设置应用程序的权限。)

WCF安全性:由于绑定只是一个BasicHttpBinding,因此该服务不需要任何有效内容。 IIS负责此事。

服务的绑定配置:

<bindings>
  <basicHttpBinding>
     <binding>
        <security mode="Transport">
           <transport clientCredentialType="Basic" />
        </security>
     </binding>
  </basicHttpBinding>

最后,为了解决第一个错误,我们删除了mex端点。此端点需要HTTP绑定。

删除:

<endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange"/>