调用WCF服务时的Random AuthenticationManager CustomTargetNameDictionary异常

时间:2009-08-07 13:44:51

标签: c# asp.net wcf web-services authentication

从ASP.Net应用程序调用WCF服务时,我一直收到此错误:

Unhandled Exception: System.InvalidOperationException

System.InvalidOperationException: The entry found in AuthenticationManager's CustomTargetNameDictionary for {URL} does not match the requested identity of host/{Hostname}.

Server stack trace: 
   at System.ServiceModel.Channels.HttpTransportSecurityHelpers.AddIdentityMapping(Uri via, EndpointAddress target)
   at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.PrepareOpen()
   at System.ServiceModel.Channels.HttpsChannelFactory.HttpsRequestChannel.OnOpen(TimeSpan timeout)
   at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
   at System.ServiceModel.Channels.ServiceChannel.OnOpen(TimeSpan timeout)
   at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
   at System.ServiceModel.Channels.ServiceChannel.CallOpenOnce.System.ServiceModel.Channels.ServiceChannel.ICallOnce.Call(ServiceChannel channel, TimeSpan timeout)
   at System.ServiceModel.Channels.ServiceChannel.CallOnceManager.CallOnce(TimeSpan timeout, CallOnceManager cascade)
   at System.ServiceModel.Channels.ServiceChannel.EnsureOpened(TimeSpan timeout)
   at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
   at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs)
   at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
   at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)

关于它的奇怪之处在于我无法在除生产Web服务器之外的任何机器上重现它,并且它只是偶尔发生。该服务需要活动目录身份验证,但我确信用户具有正确的权限集。

WCF配置似乎没有问题,因为它有时可以工作,而其他应用程序可以无错误地调用同一服务。

我已经尝试完全重新创建用户,重新创建它运行的应用程序池并重新安装应用程序。谢谢你的帮助!

2 个答案:

答案 0 :(得分:0)

这似乎与“破旧的冒充”的“旧”问题相匹配。 哪个部分或您的解决方案与凭证一起运行? 如果您的Web用户(即使他已登录到您的域)在ASP.net应用程序中正确模拟,则在调用WS(以及从那里调用AD)时,您的链可能会中断。因此,请确保您的WS使用用户上下文运行,并允许其访问AuthManager部件。如果需要,请确保在用户帐户或计算机帐户上启用了Kerberos委派。

(在PC上进行开发时可能看不到这个问题,因为您可能以管理员身份运行并具有“调试”权限。)

HTH, 托马斯

答案 1 :(得分:0)

我遇到了同样的错误。它正在努力,但我找到了解决方案。

它似乎是WCF客户端库中的缓存问题。对于每个Web服务URL,它看起来都会记住端点标识。如果对来自同一应用程序池中的代码的单个Web服务发出两个请求,那么如果它们不使用完全相同的标识,您将收到报告的错误。

在我的情况下,一个身份使用大写,另一个使用小写。因此,无论代码被调用,首先会继续正常工作,但任何使用第二个身份的代码都会一直失败,直到应用程序池重新启动。

我的代码如下

// ** Specify an identity (any identity) in order to get it past .net3.5 sp1
EndpointIdentity epi = EndpointIdentity.CreateUpnIdentity("unknown");
EndpointAddress epa = new EndpointAddress(new Uri(address), epi);

另一部分代码使用“未知”而不是“未知”