C# WCF Windows身份验证不适用于wsHttpBinding

C# WCF Windows身份验证不适用于wsHttpBinding,c#,wcf,authentication,iis,C#,Wcf,Authentication,Iis,问题是我无法使用wsHttpBinding获得windows身份验证 这是配置文件: <services> <service name="WcfService1.Service1"> <endpoint address="" bindingConfiguration="testbinding" contract="WcfService1.IService1" binding="wsHttpBinding"/> </service>

问题是我无法使用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请求未经客户端身份验证方案“协商”授权。从服务器接收到的身份验证标头为“协商OXMWCADCGGEBOMOEAGGBMBGKQHKIG9XIBAGIDAH5XMFWGAWIBBAEDAGEEPBEYDZWIWMTCWODE2MJA1MJQWWQUFAGMK8G2MAWIBBAKOGWXDT1JQLNBQUIUU0WQGJAYOAMCAQGHETAPGW1JB3JWYXBWBDU5ODGK”。 还有一个内在的例外是: “目标主体名称不正确”

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

但是,如果我将应用程序池更改为使用“ApplicationPoolIdentity”而不是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>

它运行良好(同时保留广告服务帐户),这是为什么? 我不想用basicHttpsBinding

我在客户端配置文件(使用wcftestclient)中看到了一个区别,即在使用wshttp时,它有:

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

这与此有关吗?(这里只是疯狂地猜测)


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

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

<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域必须存在才能正常工作。

很多情况取决于域的设置方式,但您可以尝试不同类型的客户端凭据类型:

<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域必须存在,它才能工作。

在客户端,生成的标识标记导致了问题

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

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

在客户端,生成的标识标记导致了问题

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

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

谢谢你的回答,但我不能使用Ntlm(由于安全限制)我设法解决了它(下面的答案)谢谢你的回答,但我不能使用Ntlm(由于安全限制)我设法解决了它(下面的答案)