WCF客户端无法访问服务原因之一:时间不同步问题

在使用WCF服务时,如果客户端调用服务时出现如下错误:
System.ServiceModel.Security.MessageSecurityException: 从另一方收到未进行安全处理或安全处理不正确的错误。有关错误代码和详细信息,请
参阅内部 FaultException。 ---> System.ServiceModel.FaultException: 消息中至少有一个安全令牌无法验证。
--- 内部异常堆栈跟踪的结尾 ---
Server stack trace:
在 System.ServiceModel.Channels.SecurityChannelFactory`1.SecurityRequestChannel.ProcessReply(Message reply, SecurityProtocolCorrelationState correlationState, TimeSpan timeout)
在 System.ServiceModel.Channels.SecurityChannelFactory`1.SecurityRequestChannel.Request(Message message, TimeSpan timeout)
在 System.ServiceModel.Security.SecuritySessionSecurityTokenProvider.DoOperation(SecuritySessionOperation operation, EndpointAddress target, Uri via, SecurityToken currentToken, TimeSpan timeout)
在 System.ServiceModel.Security.SecuritySessionSecurityTokenProvider.GetTokenCore(TimeSpan timeout)
在 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(TimeSpan timeout)
在 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)
在 System.ServiceModel.Channels.ServiceChannel.EnsureOpened(TimeSpan timeout)
在 System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
在 System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs)
在 System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
在 System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)

Exception rethrown at [0]:
在 System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
在 System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
在 CommonData.MembershipRole.IMembershipRole.ValidateUser(String username, String password)
在 CommonData.MembershipRole.MembershipRoleClient.ValidateUser(String username, String password)
在 WMSClient.LoginForm.bdlogin_DoWork(Object sender, DoWorkEventArgs e) in line:CommonData.LoggingService.Error(:0):off.CommonData.LoggingService
这种情况90%是因为客户端和服务端时间不一致造成的,客户端和服务端所允许的时间差可以是5分钟.
解决方案是客户端要和服务端进行时间同步.
可以使用命令:net time \\IP地址或服务器名 /set /yes ,但这样操作对服务器的安全有影响,目前我还没有想到好的解决方法.不知大家有什么好的方法.

你可能感兴趣的:(WCF)