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?
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.
This sounds like a timeout combined with not handling the failing services.
It takes longer to run in the morning since code has to be JIT compiled, maybe also database needs to cache data and query plans.
Here is one way to get the WCF client to clean up after itself http://nimtug.org/blogs/damien-mcgivern/archive/2009/05/26/wcf-communicationobjectfaultedexception-quot-cannot-be-used-for-communication-because-it-is-in-the-faulted-state-quot-messagesecurityexception-quot-an-error-occurred-when-verifying-security-for-the-message-quot.aspx
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With