WCF项目中客户端与服务器时间问题步无法连接的解决方案 (供自己以后参考)
来源:互联网 发布:彩票选号优化方法 编辑:程序博客网 时间:2024/05/17 04:20
WCF项目中客户端与服务器时间问题步无法连接的解决方案
出处:西西整理 作者:西西 日期:2011-4-17 15:53:21 [大中 小] 评论: 0 | 我要发表看法
新项目中使用了WCF 实现客户端与服务器的通讯。c/s架构,客户端采用winfrom实现。项目试运行期间,很多用户都抱怨系统总是无法正常登录。
查看日志发现如下异常信息:
System.ServiceModel.Security.MessageSecurityException: 从另一方收到未进行安全处理或安全处理不正确的错误。有关错误代码和详细信息,请
参阅内部 FaultException。 ---> System.ServiceModel.FaultException: 消息中至少有一个安全令牌无法验证。
WCF通讯采用了UserName安全认证方式,用Google大神搜索一番,上述异常多是因为客户端与服务器端时间不同步所引起的,WCF所提供的几种Binding客户端和服务端所允许的时间差可以是5分钟.
原因找到了,下面就是如何解决了,网上大多数方法是使用 命令:net time \\IP地址或服务器名 /set /yes 去同步客户端的时间,这种方式我直接给Pass掉了,原因如下:
通过跟用户的交流发现很多用户是故意将时间提前或推后十几分钟的,原因很多就不详细列具了。
继续找其它解决方案,在国外一个论坛上发现可以使用customBinding 修改允许的最大时间偏差。let's try it!
修改前的配置文件(删减了一些配置节)如下:
01<system.serviceModel> 02<client/> 03<services> 04 <service name="userService"> 05 <endpoint address="" binding="wsHttpBinding" bindingConfiguration="Binding_user"06 contract="Iuser"/> 07 </service> 08<bindings> 09 <wsHttpBinding> 10 <binding name="Binding_user"> 11 <security mode="Message"> 12 <transport/> 13 <message clientCredentialType="UserName" /> 14 </security> 15 </binding> 16 </wsHttpBinding> 17 </bindings> 18</system.serviceModel>1将wsHttpBinding替换为customBinding后配置文件如下:01<system.serviceModel> 02<client/> 03<services> 04 <service name="userService"> 05 <endpoint address="" binding="customBinding" bindingConfiguration="MyCustomBinding"06 contract="Iuser"/> 07 </service> 08 </services> 09 <bindings> 10 <customBinding> 11 <binding name="MyCustomBinding"> 12 <transactionFlow /> 13 <security authenticationMode="UserNameForSslNegotiated">14 <secureConversationBootstrap> 15 <localClientSettings maxClockSkew="00:59:00" />16 <localServiceSettings maxClockSkew="00:59:00" />17 </secureConversationBootstrap> 18 <localClientSettings maxClockSkew="00:59:00" />19 <localServiceSettings maxClockSkew="00:59:00" />20 </security> 21 <textMessageEncoding> 22 <readerQuotas maxStringContentLength="500000"/>23 </textMessageEncoding> 24 <httpTransport maxReceivedMessageSize="10485760" maxBufferPoolSize="524288" />25 </binding> 26 </customBinding> 27</bindings> 28</system.serviceModel>1这里将充许的最大时间偏差改为59分钟。1到这里还不算完,以上只是修改的服务端配置文件,在客户端的app.config文件中同样要修改,客户端配置修改后如下:01<system.serviceModel> 02 <bindings> 03 <customBinding> 04 <binding name="MyCustomBinding" closeTimeout="00:01:00"05 openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"06 > 07 <transactionFlow /> 08 <security authenticationMode="UserNameForSslNegotiated">09 <secureConversationBootstrap> 10 <localClientSettings maxClockSkew="00:59:00" />11 <localServiceSettings maxClockSkew="00:59:00" />12 </secureConversationBootstrap> 13 <localClientSettings maxClockSkew="00:59:00" />14 <localServiceSettings maxClockSkew="00:59:00" />15 </security> 16 <textMessageEncoding> 17 <readerQuotas maxStringContentLength="500000"/>18 </textMessageEncoding> 19 <httpTransport maxReceivedMessageSize="10485760" maxBufferPoolSize="524288" />20 </binding> 21 </customBinding> 22 </bindings> 23 <client> 24 <endpoint address="http://********/user.svc" binding="customBinding"25 bindingConfiguration="MyCustomBinding" contract="Iuser"26 name="CustomBinding_Iuser" /> 27 </client> 28 </system.serviceModel>OK,完工,初次写博,尽请拍砖。
- WCF项目中客户端与服务器时间问题步无法连接的解决方案 (供自己以后参考)
- WCF 客户端与服务器时间不同步无法连接的解决方法
- SSH中主要的配置文件记录,省得自己以后忘了,供自己参考
- SVN客户端无法连接服务器的问题
- SVN客户端无法连接服务器的问题
- Springmvc遇到的问题和解决方案(仅供自己参考,不喜勿喷)
- android项目知识点总结-(个人习惯 供自己以后参考 请勿评论)
- 客户端与服务器的连接问题
- Web开发中遇到关于spring注入的问题(尚未整理 仅供自己参考)
- 某个课程设计时用到的SQL脚本,贴在这里供自己以后参考一下
- Asmack客户端无法连接Openfire服务器问题的解决
- WCF 服务器与客户端的配置
- 某些IE客户端无法通过WCF获取数据的解决方案
- python语言的解释性执行问题(备份一下,以供以后学习参考)
- 客户端与服务器的连接
- 如果处理服务器与客户端时间不一致的问题
- StringUtils小结,供以后参考
- wcf 客户端与服务器之间在传递DataTable问题
- cf 158div2 D. Black and White Tree
- Android 根文件系统启动过程(init进程 详细分析)
- linux-时间相关结构体和函数
- 萧山JS
- c++与c#中概念的不同理解
- WCF项目中客户端与服务器时间问题步无法连接的解决方案 (供自己以后参考)
- Java指点江山
- 自己搭建的hadoop集群的全过程记录
- C# Heap(ing) Vs Stack(ing) in .NET: Part I
- Android Scroller简单用法
- 2012年36个最佳前端开发指南
- Orange数据格式
- LCD设备驱动程序2
- CentOS常用命令