【问题标题】:Client unable to authenticate when connecting to WCF service连接到 WCF 服务时客户端无法进行身份验证
【发布时间】:2010-02-09 23:34:31
【问题描述】:

我有一个托管在 Windows 服务中的 WCF 服务。该应用程序是一个 Intranet 应用程序,我以编程方式将服务和客户端上的绑定设置为:

NetTcpBinding aBinding = new NetTcpBinding(SecurityMode.Transport);
aBinding.Security.Transport.ClientCredentialType = TcpClientCredentialType.Windows;
aBinding.Security.Transport.ProtectionLevel = System.Net.Security.ProtectionLevel.EncryptAndSign;

服务和客户端都有配置了 SPN 的端点:

EndpointAddress = new EndpointAddress(uri, EndpointIdentity.CreateSpnIdentity("Service1"));

据我所知,我已经正确设置了绑定——而且我通常能够很好地连接到服务。然而,我确实遇到了这样一种情况:在运行 Windows Server 2003 R2、x64、SP2 的服务器上,当客户端尝试连接时,我立即收到以下异常:

INNEREXCEPTION -- 异常消息:

InvalidCredentialException:目标名称不正确或服务器拒绝了客户端凭据。

堆栈跟踪:

at System.Net.Security.NegoState.ProcessAuthentication(LazyAsyncResult lazyResult)
   at System.Net.Security.NegotiateStream.AuthenticateAsClient(NetworkCredential credential, String targetName, ProtectionLevel requiredProtectionLevel, TokenImpersonationLevel allowedImpersonationLevel)
   at System.ServiceModel.Channels.WindowsStreamSecurityUpgradeProvider.WindowsStreamSecurityUpgradeInitiator.OnInitiateUpgrade(Stream stream, SecurityMessageProperty& remoteSecurity)

当我尝试从域中的另一台机器连接到服务时出现异常,但如果我连接到运行该服务的同一台机器上的服务,它工作正常。

托管服务本身作为域用户帐户运行——但我尝试将该服务作为本地系统和网络服务运行,但无济于事。我检查了服务器的本地安全策略,没有发现任何问题(即“从网络访问此计算机”包括“所有人”)。

有人知道什么可以解决这个问题吗?

我想知道是否需要在 Active Directory 中针对服务的 SPN 执行某些操作?我已经阅读了一些关于使用 setspn.exe 注册或刷新 SPN 的内容,但我以前不需要这样做。为什么这适用于其他配置,而不是上述配置?

【问题讨论】:

    标签: wcf spn


    【解决方案1】:

    尝试以具有本地管理员访问权限的帐户运行该服务 - 如果您无法以这么多的权限运行该服务,那么我相信您将需要使用您所暗示的 setspn.exe。

    【讨论】:

      猜你喜欢
      • 2012-04-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-07-23
      • 2015-06-13
      • 1970-01-01
      • 2010-11-15
      • 1970-01-01
      相关资源
      最近更新 更多