windows – 通信对象System.ServiceModel.Channels.ServiceChannel不能用于通信,因为它处于Faulted状态

前端之家收集整理的这篇文章主要介绍了windows – 通信对象System.ServiceModel.Channels.ServiceChannel不能用于通信,因为它处于Faulted状态前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

The communication object,System.ServiceModel.Channels.ServiceChannel,
cannot be used for communication because it is in the Faulted state.

Windows应用程序尝试通过wsDualHttpBinding与作为Windows服务托管的WCF进行通信时,我收到此错误. WCF用于通过串行端口与设备通信.用于经常通过WCF Windows服务发送命令的Windows应用程序.

这是堆栈跟踪:

stack trace: at
System.ServiceModel.Channels.CommunicationObject.ThrowIfDisposedOrNotOpen()
at System.ServiceModel.Channels.ServiceChannel.Call(String action,
Boolean oneway,ProxyOperationRuntime operation,Object[] ins,
Object[] outs,TimeSpan timeout) at
System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage
methodCall,ProxyOperationRuntime operation) at
System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage
message)

Exception rethrown at [0]: at
System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage
reqMsg,IMessage retMsg) at
System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData&
msgData,Int32 type) at
GridSplitter.CommandServiceReference.ICommandService.SendToMultipleChannel(String[]
channel,Int32[][] locid,String cmd,Int32 cmdData) at
GridSplitter.CommandServiceReference.CommandServiceClient.SendToMultipleChannel(String[]
channel,Int32 cmdData) at
GridSplitter.MainWindow.bwChkAndSendRedeploy_DoWork(Object sender,
DoWorkEventArgs e) : 11/9/2012 11:05:58 AM

>我无法理解为什么服务会进入故障状态.
>我是否应该捕获此异常并执行一些补丁工作(如果推荐)?
> TCP绑定可以帮助我避免/删除此异常吗?

解决方法

您的问题是您的代码在服务调用生成故障后使用服务代理的实例(服务引用,由SvcUtil生成或直接从ChannelFactory创建).实现WCF的方式,一旦与该代理的调用发生错误,您就无法“重用”服务代理.

您需要在lines shown in this good post中为WCF特定要求编写适当的异常处理逻辑.无论您配置要使用的代理的实际绑定如何,都需要执行此操作.

猜你在找的Windows相关文章