匿名身份验证不适用于 WCF 服务:“.....从服务器收到的身份验证 header 是 ''”
Anonymous authentication not working for WCF service: "..... The authentication header received from the server was ''"
我们使用 IIS 7.5 托管我们的 Intranet 应用程序,这些应用程序配置为使用 Windows 身份验证。
在其中一个应用程序中,我有一个 WCF 服务,我正试图 host/call 进入。这必须具有匿名身份验证,因此我可以使用以下设置托管它:
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="myServiceBehaviour">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<basicHttpBinding>
<binding name="basicHttpBindingOverSslAnonymous">
<security mode="Transport">
<transport clientCredentialType="None"/>
</security>
</binding>
</basicHttpBinding>
</bindings>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
<services>
<service behaviorConfiguration="myServiceBehaviour"
name="xxx.yyy.Web.Mvc.Client.Services.MyService">
<endpoint address="" binding="basicHttpBinding" bindingConfiguration="basicHttpBindingOverSslAnonymous" name="BasicHttpEndpoint" contract="xxx.yyy.Wcf.IMyService">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
</system.serviceModel>
但是,尽管服务器配置为允许匿名身份验证并禁用 Windows 身份验证,但我得到的只是以下异常消息:
The HTTP request is unauthorized with client authentication scheme
'Anonymous'. The authentication header received from the server was ''
注意空验证 header。对此进行谷歌搜索是徒劳的,因为所有响应都包含在引号中(尽管使用了短语搜索运算符)。
这是基于具有以下配置的我的客户端:
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpEndpoint">
<security mode="Transport">
<transport clientCredentialType="None" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="https://xxx.local/xxx.yyy.Web.Mvc.Client/services/MyService.svc"
binding="basicHttpBinding" bindingConfiguration="BasicHttpEndpoint"
contract="MyService.IMyService" name="BasicHttpEndpoint" />
</client>
</system.serviceModel>
在浏览器中启用 Windows 身份验证工作正常,但我不想发送凭据。
好像 WCF 忽略了我的 IIS 配置:
- 匿名认证
- 模仿
- 基本身份验证
- 表单身份验证
- Windows 认证
为什么会这样?
有趣的是,将 test.txt 文件放到同一文件夹中可以很好地处理匿名设置。好像这只影响 WCF。
问题是在 IIS 中配置匿名身份验证不是唯一的步骤。
以下内容从包含我的服务的 /Services 文件夹中删除了 Intranet 样式的拒绝规则。
<location path="Services">
<system.web>
<authorization>
<allow users="*" />
</authorization>
<identity impersonate="false" />
</system.web>
</location>
这样做的最终效果是允许 /Services 文件夹中的 .NET 资产进行匿名身份验证。
我们使用 IIS 7.5 托管我们的 Intranet 应用程序,这些应用程序配置为使用 Windows 身份验证。
在其中一个应用程序中,我有一个 WCF 服务,我正试图 host/call 进入。这必须具有匿名身份验证,因此我可以使用以下设置托管它:
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="myServiceBehaviour">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<basicHttpBinding>
<binding name="basicHttpBindingOverSslAnonymous">
<security mode="Transport">
<transport clientCredentialType="None"/>
</security>
</binding>
</basicHttpBinding>
</bindings>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
<services>
<service behaviorConfiguration="myServiceBehaviour"
name="xxx.yyy.Web.Mvc.Client.Services.MyService">
<endpoint address="" binding="basicHttpBinding" bindingConfiguration="basicHttpBindingOverSslAnonymous" name="BasicHttpEndpoint" contract="xxx.yyy.Wcf.IMyService">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
</system.serviceModel>
但是,尽管服务器配置为允许匿名身份验证并禁用 Windows 身份验证,但我得到的只是以下异常消息:
The HTTP request is unauthorized with client authentication scheme 'Anonymous'. The authentication header received from the server was ''
注意空验证 header。对此进行谷歌搜索是徒劳的,因为所有响应都包含在引号中(尽管使用了短语搜索运算符)。
这是基于具有以下配置的我的客户端:
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpEndpoint">
<security mode="Transport">
<transport clientCredentialType="None" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="https://xxx.local/xxx.yyy.Web.Mvc.Client/services/MyService.svc"
binding="basicHttpBinding" bindingConfiguration="BasicHttpEndpoint"
contract="MyService.IMyService" name="BasicHttpEndpoint" />
</client>
</system.serviceModel>
在浏览器中启用 Windows 身份验证工作正常,但我不想发送凭据。
好像 WCF 忽略了我的 IIS 配置:
- 匿名认证
- 模仿
- 基本身份验证
- 表单身份验证
- Windows 认证
为什么会这样?
有趣的是,将 test.txt 文件放到同一文件夹中可以很好地处理匿名设置。好像这只影响 WCF。
问题是在 IIS 中配置匿名身份验证不是唯一的步骤。
以下内容从包含我的服务的 /Services 文件夹中删除了 Intranet 样式的拒绝规则。
<location path="Services">
<system.web>
<authorization>
<allow users="*" />
</authorization>
<identity impersonate="false" />
</system.web>
</location>
这样做的最终效果是允许 /Services 文件夹中的 .NET 资产进行匿名身份验证。