WCF Cannot be used for communication because it is in the Faulted state

Instead of using the using statement, try running your code without it.

From

using(var client = new WCFClient())
{
    // ... code
}

to

var client = new WCFClient()

// ... code

Upon doing so, we were able to see that the original WCF Cannot be used for communication because it is in the Faulted state message was caused by the using() call itself. Why? Our code that was using the WCF client was passing in invalid credentials, and the server responded with an error and changing the state of the proxy to faulted. The using() block, as we know, calls Dispose() on the object - in this case our WCF client.

Because the WCF client failed, and the WCF client was in a faulted state, calling Dispose() caused the error WCF Cannot be used for communication because it is in the Faulted state to be thrown.

We were able to see this by wrapping the code that uses the WCF client in a try...catch block.


Faulted state means there has been an unexpected exception on the server side. In an earlier call.

You should have gotten an exception at the client side too, maybe your code ignores it?

You can solve it by reopening the connection. But it seems you need better error handling.

Tags:

C#

.Net

Wcf

Service