OK, I got it. Here's what you need to do:
- Read this article: http://msdn.microsoft.com/en-us/magazine/cc163302.aspx
- Create the operation attribute and place it at the over the method in the service
Implment an IOperationBehavior with something like
public void ApplyDispatchBehavior(OperationDescription operationDescription, DispatchOperation dispatchOperation) { dispatchOperation.Formatter = new ExceptionHandlingFormatter(); }
Create the formatter that implements IDispatchMessageFormatter and do something like this:
public void DeserializeRequest(Message message, object[] parameters) { var serializer = new XmlSerializer(typeof(WagenlijstRequest), "http://services.prorail.nl/OVGS/Schemas/v10"); try { // Attempts to deserialize the object given the message body var result = serializer.Deserialize(message.GetReaderAtBodyContents()); parameters[0] = new SomeRequest(result as AnotherType); } catch (Exception e) { // In case of an exception - wraps the exception in a Dutch one + logs it var exception = new RequestDeserializationException(e); this.log.Fatal(string.Format("Error while deserializing the following request:\r\n{0}\r\nException:\r\n{1}", message, exception), exception); throw new SomeFaultType(exception).AsFaultException(); } } public Message SerializeReply(MessageVersion messageVersion, object[] parameters, object result) { return Message.CreateMessage(messageVersion, string.Empty, result); }
It comes down to being able to apply my custom desialization behevior for the operation. That behavior deserializes but with a try catch that wraps the exception in an exception with a Dutch message.