WCF at Services faulted state

wcf

I have many webservices running in my project but something odd has been happening for quite some time. My services occasionally crash for no reason with an error message "The communication object, System.ServiceModel.Channels.ServiceChannel, cannot be used for communication because it is in the Faulted state." This usually happens when I run the application first thing in the morning after which they occur less frequently. Any ideas as to what might be causing this error?

Best Answer

If a WCF service throws a FaultException, the client will have its state changed to CommunicationState.Faulted. If you then try to use this client object to call another service operation, you'll get the error

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

You might also get this error if you try to call the Close() method on a faulted client, I can't remember.

You can check the state of your client object by checking the State property. If you want to close your client properly (which you should be doing), you need to call the Abort() method if the client is in the Faulted state, and the Close() method if the client is in any other state.

Related Topic