Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WCF at Services faulted state

Tags:

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?

like image 393
Farax Avatar asked Aug 24 '10 03:08

Farax


2 Answers

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.

like image 182
Graham Clark Avatar answered Sep 22 '22 07:09

Graham Clark


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

like image 20
Shiraz Bhaiji Avatar answered Sep 25 '22 07:09

Shiraz Bhaiji