2009-07-03 31 views
1

我需要一些关于WCF和授权的帮助。 目前我有一个客户端,它调用一个Windows服务中托管的.NET远程对象,并调用WCF服务(使用wshttpbinding)。 WCF服务正在使用Windows身份验证和基于消息的安全性。如何模拟wcf调用的客户端

windows服务正在运行一个特殊的帐户。 一旦客户端调用到达.NET远程对象,thread.currentprincipal将被设置为由客户端提供的主体,以便所有操作都使用来自客户端的凭据执行。 到目前为止没有问题,现在这里出现我目前的问题: 应使用客户端用户凭据调用wcf服务。 Afaik WCF使用WindowsIdentity.GetCurrent为该调用创建授权信息。由于Thread.CurrentPrincipal保存了我想用于调用的身份,我认为(hread.CurrentPrincipal.Identity为WindowsIdentity).Impersonate()完成这项工作。

但现在我得到一个WCF安全异常,而不是此异常: System.ComponentModel.Win32Exception:没有凭据的安全包

调用堆栈提供: 在System.IdentityModel.SspiWrapper.AcquireCredentialsHandle(串包,CredentialUse意图,AuthIdentityEx &的authData) 在System.ServiceModel.Security.SecurityUtils.GetCredentialsHandle(串包,的NetworkCredential凭证,布尔isServer,串[] additionalPackages) 在System.ServiceModel.Security.SecurityUtils.GetCredentialsHandle(SecurityBindingElement SBE ,ClientCredentials clientCredentials) 在System.ServiceModel.Security.SecurityUtils.GetCredentialsHandle(SecurityBindingElement SBE,的BindingContext上下文) 在System.ServiceModel.Security.SecuritySessionSecurityTokenProvider.OnOpening() 在System.ServiceModel.Security.WrapperSecurityCommunicationObject.OnOpening() 在System.ServiceModel。 Channels.CommunicationObject.Open(时间跨度超时) 在System.ServiceModel.Security.CommunicationObjectSecurityTokenProvider.Open(时间跨度超时) 在System.ServiceModel.Security.SecurityUtils.OpenTokenProviderIfRequired(SecurityTokenProvider tokenProvider,时间跨度超时) 在System.ServiceModel.Security。 SecuritySessionClientSettings`1.ClientSecuritySessionChannel.OnOpen(TimeSpan timeout) at System.ServiceModel.Channels.CommunicationObject。开放(时间跨度超时) 在System.ServiceModel.Channels.ServiceChannel.OnOpen(时间跨度超时) 在System.ServiceModel.Channels.CommunicationObject.Open(时间跨度超时) 在System.ServiceModel.Channels.ServiceChannel.CallOpenOnce.System.ServiceModel .Channels.ServiceChannel.ICallOnce.Call(ServiceChannel信道,时间跨度超时) 在System.ServiceModel.Channels.ServiceChannel.CallOnceManager.CallOnce(时间跨度超时,CallOnceManager级联) 在System.ServiceModel.Channels.ServiceChannel.EnsureOpened(时间跨度超时) (String action,Boolean oneway,ProxyOperationRuntime operation,Object [] ins,Object [] outs,TimeSpan timeout) at System.ServiceModel.Channels.ServiceChannel.Call(String action,Boolean单向,ProxyO perationRuntime操作,Object [] ins,Object []出) at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall,ProxyOperationRuntime operation) at System.ServiceModel.Channels.ServiceChannelProxy。调用(即时聊天消息)

THX对于任何帮助 马丁

编辑:我犯了一个错误,导致这个例外,因为我忘了创建模拟后的ChannelFactory,但现在我得到另一个例外,我不知道如何处理它: System.IO.FileLoadException:无法加载文件或程序集'System.IdentityModel.Selectors,Version = 3.0.0.0,Culture = neutral,PublicKeyToken = b77a5c561934e089'或其依赖项之一。未提供所需的模拟级别,或提供的模拟级别无效。 (来自HRESULT的例外:0x80070542)

回答