asp.net - 401 客户端 'Negotiate' ,服务器 'Negotiate,NTLM' 当调用 WCF 服务器到服务器时

标签 asp.net web-services wcf authentication iis

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

HTTP 请求未经客户端身份验证方案“协商”的授权。从服务器收到的身份验证 header 是“Negotiate,NTLM”。]

我为 WCF 托管站点启用了匿名和 Windows 身份验证。我开始使用的 Web 应用程序托管在与 WCF 服务不同的服务器上,并且在 ASP.NET 2.0 和 Windows Server 2008 R2 Enterprise 上运行。我已经使用allowNtlm 创建了客户端行为,并在客户端将 NetworkSecurity: LAN Manager 身份验证级别设置为 Send LM & NTLM...。在托管端,它设置为仅发送 NTLMv2 响应...我不知道这是否会影响服务器/服务处理身份验证的方式。我还尝试在客户端上将 allowedImpersonationLevel 设置为 Impersonation ,幸运的是,这不起作用(因为不需要模拟)。对于与 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 进程的帐户自动获取它吗?

最佳答案

为了回答第一个问题,错误消息准确地告诉了我它所说的内容;我没有被授权。告诉我客户端身份验证方案和服务器 header 的行只是额外信息,并不表示冲突。这实际上是确认配置正确。

在临时环境中,问题被掩盖了,因为 WCF 服务和 Web 应用程序托管在同一服务器上。问题是 Web 应用程序的站点默认配置为对匿名用户使用 IUSR(或 IUSR_Server)(本地帐户)。这是正在传递的用户(我相信它等于 CredentialCache.DefaultNetworkCredentials)。当它们位于不同的服务器上时,服务器 2 上的 WCF 显然无法对服务器 1 用户进行身份验证。解决方案是在 IIS 中,右键单击“匿名身​​份验证”>“编辑...”> 检查应用程序池身份(在我的例子中是域帐户)或输入特定用户的域帐户。

关于asp.net - 401 客户端 'Negotiate' ,服务器 'Negotiate,NTLM' 当调用 WCF 服务器到服务器时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22460150/

相关文章:

c# - 从 WCF 服务器端获取 Windows 用户名

c# - 对象引用未设置为对象的实例......但它是?

java - Resteasy 可选路径元素

c# - 完全卡住了,简短地在标题中解释,涵盖了 c# asp.net 控件和 html 代码以及一点 javascript

linux - 使用 gSOAP 通过 WCF Windows 服务下载文件

web-services - 如果 Web 服务已经使用 SSL,我是否需要在网页上使用 SSL?

c# - 从 IAuthorizationPolicy 设置 Thread.CurrentPrincipal?

wcf - 如何使用一个 WcfFacility 托管多个服务

c# - OracleBulkCopyOptions.Default 和 OracleBulkCopyOptions.UseInternalTransaction 之间的区别。

mysql - 如何使用 SQL MINUS 关键字