【问题标题】:Anonymous authentication not working for WCF service: "..... The authentication header received from the server was ''"匿名身份验证不适用于 WCF 服务:“.....从服务器收到的身份验证标头为 ''”
【发布时间】:2015-11-24 12:47:23
【问题描述】:

我们使用 IIS 7.5 托管我们的 Intranet 应用程序,这些应用程序配置为使用 Windows 身份验证。

在其中一个应用程序中,我有一个正在尝试托管/调用的 WCF 服务。这必须具有匿名身份验证,因此我可以使用以下设置托管它:

<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 身份验证,但我得到的只是以下异常消息:

HTTP 请求未经客户端身份验证方案授权 '匿名的'。从服务器收到的身份验证标头是 ''

注意空的身份验证标头。谷歌搜索是徒劳的,因为所有响应都在引号中包含某些内容(尽管使用了短语搜索运算符)。

这是基于我的客户端,它具有以下配置:

<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。

【问题讨论】:

    标签: wcf authentication iis iis-7.5


    【解决方案1】:

    问题在于在 IIS 中配置匿名身份验证并不是唯一的步骤。

    以下内容从包含我的服务的 /Services 文件夹中删除 Intranet 样式的拒绝规则。

      <location path="Services">
        <system.web>
          <authorization>
            <allow users="*" />
          </authorization>
          <identity impersonate="false" />
        </system.web>
      </location>
    

    这样做的最终结果是允许 /Services 文件夹中的 .NET 资产进行匿名身份验证。

    【讨论】:

    • 这是在什么文件中设置的?
    • 啊,对不起,是Web.config
    • 感谢您对旧线程的评论回复。这是服务 web.config 还是在 IIS 目录中?
    • 没问题。服务 web.config,因此适用于应用程序。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-11-24
    • 2012-10-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多