Detailed fault information is not deserialized when specifying a custom serializer

I use custom XmlObjectSerializerin my application. For this, I replace XmlSerializerOperationBehaviorwith MyOperationBehavior, which looks something like this:

public class MyOperationBehavior : DataContractSerializerOperationBehavior
{
    public override XmlObjectSerializer CreateSerializer(Type type, string name, string ns, IList<Type> knownTypes)
    {
        return new MySerializer();
    }

    public override XmlObjectSerializer CreateSerializer(Type type, XmlDictionaryString name, XmlDictionaryString ns, IList<Type> knownTypes)
    {
        return new MySerializer();
    }
}

The problem is that in doing so, any errors are deserialized into a non-general one FaultException, and not FaultException<TDetail>, and I cannot access the details of the failure.

After some research, I found that the root of the problem is that, inheriting from DataContractSerializerOperationBehavior, .NET internally sets the FaultFormatter value to DataContractSerializerFaultFormatter, which does not know how to deserialize the error details (and not XmlSerializerFaultFormatter). The problem, of course, is not MySerializer, as it is FaultExceptionthrown before it gets into my method ReadObject.

, , , WCF ? FaultFormatter, , , .

+2
1

FaultExceptions. , , , , , - . , .

, XmlSerializerOperationBehavior MyOperationBehavior (, , ). , , , . , , MyOperationBehavior XmlSerializerOperationBehavior - .

description.Behaviors.Insert(0, new MyOperationBehavior());

, , , , , , .

0

All Articles