Sunday, 8 July 2018

ASP.NET ERROR : System.ServiceModel.CommunicationObjectFaultedException: 'The communication object, System.ServiceModel.Channels.ServiceChannel, cannot be used for communication because it is in the Faulted state.'

This Error happens because a .NET exception has occurred at WCF service server side. Due to this error Communication Object (or Proxy Class)  has been disturbed results in the communication break-down between WCF Service and Client and hence, came to a faulted state.


Things You can do in order to cope with this:

Handle the Exception(Use Try- Catch / Throw an Exception): Don't Catch the Dot Net Exception (there is a reason why you should not use Dot Net Exception: As you are using WCF, whose one of the motto is Interoperability. By using .NET Exception you are sacrificing that).
Use FaultException Instead !!!

If you want to recreate the Communication channel between WCF Service and Client, you just need to instantiate the Proxy Class.

You can check whether the communication is in faulted state or not by :

if(client.InnerChannel.State != System.ServiceModel.CommunicationState.Faulted)
{
   // call service - everything's fine
}
else
{
   // channel faulted - re-create your client and then try again
}

Happy Coding !!! 

No comments:

Post a Comment

SQL Audits

1. sys.server_audits What it is: Lists all server-level audit objects . An audit is the top-level object that defines: Where to wri...