C# Global.asax.cs中的静态ChannelFactory抛出CommunicationObjectFaultedException
我在Global.asax.cs文件中使用以下代码:C# Global.asax.cs中的静态ChannelFactory抛出CommunicationObjectFaultedException,c#,asp.net,wcf,global-asax,C#,Asp.net,Wcf,Global Asax,我在Global.asax.cs文件中使用以下代码: public static readonly IMyCommunicationService GlobalCommunicationChannel = new ChannelFactory<IMyCommunicationService>("NetTcpBinding_IMyCommunicationService").CreateChannel(); 公共静态只读IMyCommunicationService全
public static readonly IMyCommunicationService GlobalCommunicationChannel =
new ChannelFactory<IMyCommunicationService>("NetTcpBinding_IMyCommunicationService").CreateChannel();
公共静态只读IMyCommunicationService全局通信通道=
新的ChannelFactory(“NetTcpBinding_IMyCommunicationService”).CreateChannel();
从每个网站,我都在访问静态变量“GlobalCommunicationsChannel”
到目前为止,这项工作做得很好。但有时,在生产环境中,我会得到一个通信对象faultedException。它表示我无法使用GlobalCommunicationsChannel对象,因为对象“System.ServiceModel.Channel.ServiceChannel”处于故障状态
我没有得到更多的信息几分钟后,它又开始工作了。不知道为什么。我认为这种联系是重新建立起来的
是什么原因导致此错误?有没有一种方法可以避免将来出现这种错误,而不必到处添加try/catch和retry
提前非常感谢您的回答 检查您的SessionMode值: 默认情况下,此属性的值 是允许的,这意味着如果 客户端使用基于会话的绑定 通过WCF服务实现 服务建立并使用 提供的会议记录。() 在服务合同中,尝试将会话设置为NotAllowed
[ServiceContract(SessionMode=SessionMode.NotAllowed)]
。因此,您可以检查您的问题是否可以在10个会话中复制。您使用的是什么会话模式和InstanceContextMode?InstanceContextMode=InstanceContextMode.Single,ConcurrencyMode=ConcurrencyMode.Multiple。线程安全是在服务器端完成的。据我所知,我不需要为ServiceChannel在客户端执行任何线程安全操作。但是SessionMode呢?可能是您的会话没有终止。我没有找到SessionMode的任何设置。它应该通过我的MyCommunicationService类,如InstanceContextMode和ConcurrencyMode吗?或者是我必须在web.config文件中添加的东西?我想它使用的是默认值,因为我还没有找到这个设置。您好。我已经尝试过了,但是现在我得到了以下错误:契约不允许会话,但是绑定'NetTcpBinding'不支持数据报或者没有正确配置来支持它。我将尝试[ServiceContract(SessionMode=SessionMode.Required)]。