Here are a few snippets of my code (using tcp protocol)
Interface....
[ServiceContract()]
interface IWcfDocumentManager
{
[FaultContract(typeof(MyErrorFault))]
byte[] Document(DocumentData documentData, int pageId, bool encrypt)
}
Generic fault
[DataContract()]
public class MyErrorFault
{
private string report;
public MyErrorFault(string message)
{
this.report = message;
}
[DataMember]
public string Message
{
get { return this.report; }
set { this.report = value; }
}
}
I throw the fault in this way
throw new FaultException<MyErrorFault>(new MyErrorFault("Test fault"), new FaultReason("test reason"));
and in the client i catch the fault using this method..
catch (TimeoutException timeProblem)
{
Console.WriteLine("The service operation timed out. " + timeProblem.Message);
Console.ReadLine();
}
catch (FaultException<MyErrorFault> fault)
{
Console.WriteLine(fault.Detail.Message);
Console.ReadLine();
}
catch (FaultException unknownFault)
{
Console.WriteLine("An unknown exception was received. " + unknownFault.Message);
Console.ReadLine();
}
catch (CommunicationException commProblem)
{
Console.WriteLine("There was a communication problem. " + commProblem.Message + commProblem.StackTrace);
Console.ReadLine();
}
But it always jumps into the highlighted part of the errorhandler. Any help would be much appreciated.