【发布时间】:2014-03-17 16:40:05
【问题描述】:
好的,我已经阅读了我能找到的关于此错误的所有主题和问题,但令人惊讶的是还没有找到解决方案。我试图在我的 IIS 托管的 WCF 服务 (.NET 4.0) 上要求 Windows 身份验证,到目前为止,该服务一直是可选的。我在服务器上有一个启用 Windows 身份验证的端点已经有一段时间了,有几个远程应用程序成功使用了它。我现在正尝试将我们的 Web 应用程序和其他使用 WCF 服务的服务器应用程序切换到此安全端点,方法是为它们提供与工作远程客户端完全相同的客户端配置,但服务器应用程序正在接收带有消息的 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 设置为 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>
我的第一个问题是,这条错误消息真正告诉我什么?它说客户端方案是协商,服务器响应协商,NTLM。如果服务器提供 Negotiate 并且客户端正在使用 Negotiate,那有什么问题?
显然,第二个问题是哪里出了问题,我该如何让它发挥作用?
编辑
好吧,这很愚蠢。问题似乎是没有传递凭据。早在网站开发时,我就开始编写代码以在代码中显式设置凭据,但在此过程中,found that it was already working without explicitly setting them。所以该代码仍然被注释掉。这是在 IIS 6 上运行的。现在在 IIS 7 上运行,它似乎只有在我在代码中明确设置凭据时才有效。我可以使用 w3wp 进程的帐户自动获取它吗?
【问题讨论】:
标签: asp.net web-services wcf authentication iis