WCF in failed service state

I have many web services working in my project, but something strange has been happening for quite some time. My services sometimes crash for no reason with the 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 start the application first thing in the morning, after which they are less common. Any ideas as to what might cause this error?

+7
wcf
source share
2 answers

If the WCF service throws a FaultException , the client changes its state to CommunicationState.Faulted . If you then try to use this client object to invoke another service operation, you will receive an error message

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

You can also get this error if you try to call the Close() method on a failed client, I cannot remember.

You can check the status of your client object by specifying the State property. If you want to close your client correctly (what you should do), 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.

+9
source share

This sounds like a timeout coupled with a lack of handling failed services.

It takes longer in the morning, since the code must be compiled by JIT, it may also be necessary 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

+5
source share

All Articles