401客户端'协商',服务器'协商,NTLM'调用WCF服务器到服务器

时间:2014-03-17 16:40:06

标签: asp.net web-services wcf authentication iis

好的,我已经阅读过每一个帖子&问题我可以找到这个错误,并且令人惊讶地没有找到解决方案。我试图在我的IIS托管的WCF服务(.NET 4.0)上要求Windows身份验证,到目前为止,该服务是可选的。我已经在服务器上提供了一个启用Windows身份验证的端点,但有几个远程应用程序成功使用它。我现在尝试将使用WCF服务的Web应用程序和其他服务器应用程序切换到此安全端点,方法是为它们提供与工作远程客户端完全相同的客户端配置,但服务器应用程序正在接收401消息:

The HTTP request is unauthorized with client authentication scheme 'Negotiate'. The authentication header received from the server was 'Negotiate,NTLM'.]

我为WCF托管网站启用了匿名和Windows身份验证。我开始使用的Web应用程序托管在与WCF服务不同的服务器上,并且运行在ASP.NET 2.0和Windows Server 2008 R2 Enterprise上。我已经使用allowNtlm创建了一个客户端行为,并将NetworkSecurity:LAN Manager身份验证级别设置为Send LM& NTLM ......在客户端。在托管端,它被设置为发送NTLMv2仅响应...我不知道这是否会影响服务器/服务处理身份验证的方式。我也试过在客户端上设置allowedImpersonationLevel模仿,谢天谢地,没有工作(因为假冒不应该是必要的)。对于在与Web应用程序相同的服务器上运行的Windows服务和控制台应用程序,我们似乎得到了相同的结果。

这是我的服务器配置:

<binding name="WindowsSecuredBinding">
    <security mode="Transport">
        <transport clientCredentialType="Windows" />
    </security>
</binding>
...
<service behaviorConfiguration="OMWebServices.QueueServiceBehavior"
    name="OMWebServices.QueueService">
    <endpoint address="" binding="basicHttpBinding" name="QueueEndpoint"
      bindingName="" contract="OMWebServices.IQueueService" />
    <endpoint binding="basicHttpBinding" bindingConfiguration="WindowsSecuredBinding"
      name="QueueSecuredEndpoint" contract="OMWebServices.IQueueService" />
    <endpoint address="mex" binding="mexHttpBinding" name="QueueMetadataEndpoint"
      contract="IMetadataExchange" />
  </service>
...
<behavior name="OMWebServices.QueueServiceBehavior">
    <serviceMetadata httpGetEnabled="true" />
    <serviceDebug includeExceptionDetailInFaults="true" />
</behavior>

这是客户端配置:

<endpoint address="https://.../QueueService.svc" binding="basicHttpBinding" bindingConfiguration="QueueSecuredEndpoint" behaviorConfiguration="OMServiceBehavior" contract="OMQueueService.IQueueService" name="QueueSecuredEndpoint" />

<binding name="QueueSecuredEndpoint" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536" messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered" useDefaultWebProxy="true">
  <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384" />
  <security mode="Transport">
    <transport clientCredentialType="Windows" proxyCredentialType="None" realm="" />
    <message clientCredentialType="UserName" algorithmSuite="Default" />
  </security>
</binding>
....
<!-- The behavior I tried that didn't make a difference -->
<behavior name="OMServiceBehavior">
  <clientCredentials>
    <windows allowedImpersonationLevel="Impersonation" allowNtlm="True"/>
  </clientCredentials>
</behavior>

我的第一个问题是,这个错误信息告诉我的是什么?它说客户端方案是Negotiate,服务器响应Negotiate,NTLM。如果服务器提供Negotiate并且客户端正在使用Negotiate,那么问题是什么?

第二个问题显然是错误的,我该如何使其发挥作用?

修改
这是愚蠢的。问题似乎是没有传递凭据。当网站开发时,我开始编写代码以在代码中明确设置凭据,但在此过程中,found that it was already working without explicitly setting them。所以代码仍然被注释掉了。这是在IIS 6上运行。现在在IIS 7上运行,它似乎只有在我的代码中明确设置凭据才有效。我可以使用w3wp进程自动获取它吗?帐户?

5 个答案:

答案 0 :(得分:7)

要回答第一个问题,错误信息正在告诉我它的确切内容;我没有被授权。告诉我客户端身份验证方案和服务器头的行只是额外信息,而不是冲突的指示。实际上确认配置是正确的。

在暂存环境中,问题被屏蔽,因为WCF服务和Web应用程序托管在同一台服务器上。问题是Web应用程序的站点被配置为默认情况下为匿名用户使用IUSR(或IUSR_Server),一个本地帐户。这是传递的用户(我相信它等于CredentialCache.DefaultNetworkCredentials)。当它们位于不同的服务器上时,服务器2上的WCF显然无法验证服务器1用户。解决方案是在IIS中,右键单击匿名身份验证&gt;编辑...&GT;检查应用程序池标识(在我的情况下是域帐户)或输入特定用户的域帐户。

答案 1 :(得分:2)

这只是意味着您的客户端和服务器使用不同的身份验证方案。

在您的客户端配置中,您已设置

<transport clientCredentialType="Windows" proxyCredentialType="None" realm="" />

和消息安全

<message clientCredentialType="UserName" algorithmSuite="Default" />

因此,您可能会遇到错误。这些链接可能会帮助您。

此外,在您的客户端配置

<endpoint address="https://.../QueueService.svc" binding="basicHttpBinding" bindingConfiguration="QueueSecuredEndpoint" behaviorConfiguration="OMSServiceBehavior" contract="OMQueueService.IQueueService" name="QueueSecuredEndpoint" />

behaviorConfiguration="OMSServiceBehavior"更改behaviorConfiguration 到behaviorConfiguration="OMWebServices.QueueServiceBehavior"

您是否也尝试使用TransportCredentialOnly?如果没有,最好试试这个http://msdn.microsoft.com/en-us/library/ff648505.aspx

<security mode="TransportCredentialOnly">
    <transport clientCredentialType="Windows" />
</security>

答案 2 :(得分:2)

我遇到此错误的问题与配置无关但具体 a WCF Service calling another on the same machine

因为这影响了通过C#控制台应用程序部分配置的新服务器,我通过受影响的服务器执行这样的代码来解决它:

const string userRoot = "HKEY_LOCAL_MACHINE";
const string subkey = @"SYSTEM\CurrentControlSet\Control\Lsa\MSV1_0";
const string keyName = userRoot + @"\" + subkey;
Registry.SetValue(keyName, "BackConnectionHostNames", hostnamesOnServer.ToArray(), RegistryValueKind.MultiString);

Windows Server 2012上不需要重新启动。

答案 3 :(得分:0)

这显然也可能是您的凭据未正确传递的问题。我需要:

Client.ClientCredentials.Windows.ClientCredential.UserName = User;
Client.ClientCredentials.Windows.ClientCredential.Password = Password;

代替:

Client.ClientCredentials.UserName.UserName = User;
Client.ClientCredentials.UserName.Password = Password;

(奇怪的是,第二种方法偶尔对我有用,但并非总是如此。)

答案 4 :(得分:0)

我在这里报道了完全相同的问题。用于凭据的AD帐户已更改密码。一旦我使用了新密码,它便开始工作。

对于错误的密码情况,此错误非常容易引起误解。

相关问题