我正在使用几个使用 WIF 和 STS 提供程序保护的 WCF 服务(全部使用开箱即用的 Microsoft 代码和示例)。这些服务都是使用 .NET 3.5 构建的,并且最近都更新到了 .NET 4.0。与服务关联的所有.dll 也已更新到 4.0。这些服务多年来一直按原样工作,直到我更新了框架版本。
现在的问题是,当调用由 STS WCF 服务保护的 WCF 服务时,在将令牌传递回调用由 STS 保护的 WCF 服务的客户端应用程序后会生成错误:
从另一方收到不安全或不正确安全的故障。有关故障代码和详细信息,请参阅内部 FaultException。
HResult -2146233087
{“处理消息中的安全令牌时出错。”}
服务器堆栈跟踪:在 System.ServiceModel.Channels.SecurityChannelFactory
1.SecurityRequestChannel.ProcessReply(Message reply, SecurityProtocolCorrelationState correlationState, TimeSpan timeout) at System.ServiceModel.Channels.SecurityChannelFactory
1.SecurityRequestChannel.Request(Message message, TimeSpan timeout) at System.ServiceModel.Security.SecuritySessionSecurityTokenProvider.DoOperation(SecuritySessionOperation operation, EndpointAddress target, Uri via, SecurityToken currentToken, TimeSpan timeout) at System.ServiceModel.Security.SecuritySessionSecurityTokenProvider.GetTokenCore(TimeSpan超时) 在 System.IdentityModel.Selectors.SecurityTokenProvider.GetToken(TimeSpan timeout) 在 System.ServiceModel.Security.SecuritySessionClientSettings`1.ClientSecuritySessionChannel.OnOpen(TimeSpan timeout) 在 System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout) 在 System .ServiceModel.Channels.ServiceChannel.OnOpen(时间跨度超时)
在 System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout) 在 System.ServiceModel.Channels.ServiceChannel.CallOpenOnce.System.ServiceModel.Channels.ServiceChannel.ICallOnce.Call(ServiceChannel channel, TimeSpan timeout) 在 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)在 [0] 处重新抛出异常:在 System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type) 在 MyProject.IMyService 的 System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)。 GetInfo() 在 MyProject.Proxy.GetInfo() 在 c:\Projects\Proxy.cs:line 36
深入挖掘它还显示:
InvalidSecurityToken作为 InnerException.Code.Subcode.Name 属性值。
因此,我查看了以下内容,这些都表明系统上的时钟存在问题,但都没有奏效:
http://blogs.msdn.com/b/dhrubach/archive/2009/12/14/9936037.aspx
从另一方收到不安全或安全错误。(使用 SAML 时)
http://blogs。 msdn.com/b/xiaowen/archive/2009/03/26/tip-add-a-clock-skew-to-prevent-some-security-faults.aspx?Redirected=true
我已附加到这些服务中的调试器并尝试遍历代码,但找不到罪魁祸首。有谁知道我可能在哪里不对?
编辑:有趣的是 STS 服务中 WIF 的困难部分进行身份验证工作!我已打开日志记录并捕获以下内容:
Service authorization succeeded.
Service: http:// localhost:4068 /MyID/MyID.svc
Action: http://schemas.xmlsoap.org/ws/2005/02/trust/RST/Issue
ClientIdentity: Domain\allen; S-1-5-21-1234567890-1234567895-0987654321-45678
AuthorizationContext: uuid-22fad22a-22fe-123c-9b69-a22c23f569ce-99
ActivityId: <null>
ServiceAuthorizationManager: <default>
我还打开了 WCF 登录.config
以查看 .svc 文件,但它们没有产生任何指出问题的错误信息。就像 STS 说:“嘿,您已通过身份验证,我们通过了您并生成了令牌,现在我们完成了!” 似乎调用客户端不喜欢令牌。然而,这一直有效,直到我更改了框架版本。据我所知,从 3.5 -> 4.0 开始,WIF 没有任何重大变化,但较大的变化发生在 4.5 中,其中 WIF 被集成到框架中。
所以所有的授权都有效,只是我想客户接受的令牌有问题吗?