This is what I ideally want to do
public void AfterReceiveReply(ref Message reply, object correlationState)
{
if (reply.IsFault)
{
FaultException exp = reply.GetBody<FaultException>();
if (exp.Code.Name == "MyFaultCode")
{
//Do something here
}
}
}
but I get this exception
Error in line 1 position 82. Expecting element 'FaultException' from namespace 'http://schemas.datacontract.org/2004/07/System.ServiceModel'.. Encountered 'Element' with name 'Fault', namespace 'http://schemas.xmlsoap.org/soap/envelope/'.
when I try to do
FaultException exp = reply.GetBody<FaultException>();
From the server side this is how I throw the exception.
public object AfterReceiveRequest(ref Message request, IClientChannel channel, InstanceContext
instanceContext)
{
throw new FaultException("MyFaultCode", new FaultCode("MyFaultCode"));
}
Can someone please tell me how to deserialize the Fault Exception from the message so that I can access the FaultCode?