客户端在连接到WCF服务时无法进行身份验证

时间:2010-02-09 23:34:31

标签: wcf spn

我在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的内容,但我之前不需要这样做。为什么这会与其他配置一起使用而不是上面的配置?

1 个答案:

答案 0 :(得分:0)

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