【问题标题】:WCF Windows authentication not working with wsHttpBindingWCF Windows 身份验证不适用于 wsHttpBinding
【发布时间】:2017-08-16 21:14:52
【问题描述】:

问题是我无法使用 wsHttpBinding 获得 Windows 身份验证。

这是配置:

<services>
  <service name="WcfService1.Service1">
    <endpoint address="" bindingConfiguration="testbinding" contract="WcfService1.IService1" binding="wsHttpBinding"/>
  </service>
</services>
<bindings>
  <wsHttpBinding>
    <binding name="testbinding">
      <security mode="Transport">
        <transport clientCredentialType="Windows"/>
      </security>
    </binding>
  </wsHttpBinding>
</bindings>

这是尝试调用方法时服务器的响应: HTTP 请求未经客户端身份验证方案“协商”的授权。从服务器收到的身份验证标头是“协商 oXMwcaADCgEBomoEaGBmBgkqhkiG9xIBAgIDAH5XMFWgAwIBBaEDAgEepBEYDzIwMTcwODE2MjA1MjQwWqUFAgMK8G2mAwIBKakOGwxDT1JQLlNBQUIuU0WqGjAYoAMCAQGhETAPGw1jb3JwYXBkbw”。 还有一个内部异常说: "目标主体名称不正确"

我在 IIS 中设置了一个新站点,用于测试目的,启用了 Windows 身份验证并禁用了其他所有功能(我没有进行任何 ASP 模拟/双跳)。 Windows 身份验证的提供程序是 Negotiate、Ntlm。内核模式身份验证已启用。 应用程序池使用 Active Directory 服务帐户运行。 最终的目标是使用 Kerberos 进行身份验证,但由于它甚至不能与 Ntlm 一起使用,所以我还没有开始使用 SPN 和那些让 kerberos 工作的东西。

但是,如果我将应用程序池更改为使用“ApplicationPoolIdentity”而不是 AD 服务帐户运行,它会起作用吗? 我必须使用 AD 服务帐户运行应用程序池。

如果我将配置更改为:

<services>
  <service name="WcfService1.Service1">
    <endpoint address="" bindingConfiguration="hbinding" contract="WcfService1.IService1" binding="basicHttpsBinding"/>
  </service>
</services>
<bindings>
  <basicHttpsBinding>
    <binding name="hbinding">
      <security mode="Transport">
        <transport clientCredentialType="Windows"/>
      </security>
    </binding>
  </basicHttpsBinding>

它工作正常(保留 AD 服务帐户),这是为什么呢? 我不想使用 basicHttpsBinding

我发现客户端配置文件(使用 wcftestclient)与使用 wshttp 时有所不同:

  <identity>
      <userPrincipalName value="serviceaccount@contoso.com" />
  </identity>

这和这个有关系吗? (这里只是胡乱猜测)

端点是 https,Windows Server 2012R2 上的 IIS 8。

【问题讨论】:

    标签: c# wcf authentication iis


    【解决方案1】:

    这在很大程度上取决于您的域是如何设置的,但您可以尝试不同类型的客户端凭据类型:

    <services>
      <service name="WcfService1.Service1">
        <endpoint address="" bindingConfiguration="testbinding" contract="WcfService1.IService1" binding="wsHttpBinding"/>
      </service>
    </services>
    <bindings>
      <wsHttpBinding>
        <binding name="testbinding">
          <security mode="Transport">
            <transport clientCredentialType="Ntlm"/>
          </security>
        </binding>
      </wsHttpBinding>
    </bindings>
    

    此外,使用 wsHttpBinding 会在幕后进行协商。由于没有具体定义该协商的指导,因此有时将其关闭是有意义的:

    <services>
      <service name="WcfService1.Service1">
        <endpoint address="" bindingConfiguration="testbinding" contract="WcfService1.IService1" binding="wsHttpBinding"/>
      </service>
    </services>
    <bindings>
      <wsHttpBinding>
        <binding name="testbinding">
          <security mode="Transport">
            <message negotiateServiceCredential="false" />
          </security>
        </binding>
      </wsHttpBinding>
    </bindings>
    

    必须存在 Kerberos 域才能正常工作。

    【讨论】:

    • 感谢您的回答,但我无法使用 Ntlm(由于安全限制)我设法解决了它(答案如下)
    【解决方案2】:

    在客户端,生成的身份标签导致了问题

    <identity>
      <userPrincipalName value="serviceaccount@contoso.com" />
    </identity>
    

    如果我清除该值,它就可以正常工作。 所以我在 web.config 中清除了该值。 我现在可以设置 kerberos,它也可以正常工作,我也要尝试设置 servicePrincipalName 标记。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-11-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-10-25
      • 1970-01-01
      相关资源
      最近更新 更多