是否可以仅使用 BasicHttpBinding-binding
在 IIS 中使用 SSL 和基本身份验证设置 WCF 服务?
(我不能使用 wsHttpBinding-binding
)
该站点托管在 IIS 7 上,并设置了以下身份验证:
- 匿名访问:关闭
- 基本身份验证:开启
- 集成 Windows 身份验证:关闭
服务配置:
<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>
我尝试了两种类型的绑定(bind),但有两个不同的错误:
- 1. IIS 错误:
'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> <security mode="TransportCredentialOnly"> <transport clientCredentialType="Basic"/> </security> </binding> </basicHttpBinding> </bindings>
- 2. IIS 错误:
Security settings for this service require 'Anonymous' Authentication but it is not enabled for the IIS application that hosts this service.
<bindings> <basicHttpBinding> <binding> <security mode="Transport"> <transport clientCredentialType="Basic"/> </security> </binding> </basicHttpBinding> </bindings>
有人知道如何正确配置吗? (是否可能?)
最佳答案
经过一番挖掘并向几位同事提出了一些问题后,我们终于解决了这个问题。
重要的是要了解在这种情况下有两个方面的安全性。 IIS 安全和 WCF 安全。
IIS 安全:启用 SSL 并启用基本身份验证。禁用匿名身份验证。 (当然,创建一个 windows 帐户/组并在 IIS 中设置您的应用程序的权限。)
WCF 安全性:因为绑定(bind)只是一个 BasicHttpBinding,所以该服务不需要验证任何内容。 IIS 对此负责。
服务的绑定(bind)配置:
<bindings>
<basicHttpBinding>
<binding>
<security mode="Transport">
<transport clientCredentialType="Basic" />
</security>
</binding>
</basicHttpBinding>
最后,为了解决第一个错误,我们删除了 mex 端点。此端点需要 HTTP 绑定(bind)。
已删除:
<endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange"/>
关于wcf - 如何在 IIS 中将 WCF 与 basichttpbinding only、SSL 和 Basic Authentication 一起使用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2904883/