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

faultedservicestatewcfwindows

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

I am getting this error, when windows application is trying to communicate with WCF hosted as Windows Service via wsDualHttpBinding. The WCF is used to communicate with a device over serial port. Windows application used to send command frequently via WCF windows service.

Here's the stack trace:

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[][] locid, String cmd, Int32 cmdData) at
GridSplitter.MainWindow.bwChkAndSendRedeploy_DoWork(Object sender,
DoWorkEventArgs e) : 11/9/2012 11:05:58 AM

  1. I couldn't understand why the service is going into faulted state.
  2. Should I catch this exception and perform some patch work (if recommended)?
  3. Can TCP binding help me to avoid/remove this exception?

Best Answer

Your problem is your code is using the instance of the service proxy (Service Reference, generated by SvcUtil or created directly from ChannelFactory) after the service call has generated a fault. The way WCF is implemented, you cannot "re-use" a service proxy once a call with that proxy has thrown a fault.

You need to write proper exception handling logic along the lines shown in this good post for WCF specific requirements. This needs to be done regardless of the actual binding you configure the proxy to use.

Related Topic