Jon Archway
Jon Archway

Reputation: 4892

IErrorHandler Get Original Message

I have a WCF error handler that uses the IErrorHandler interface. In the HandleError method of this error handler I write the error exception to the log. This all works fine. However, I have a requirement to also write the actual message that raised the exception to the log as well and this is not something passed into the HandleError method.

So, I have been looking at OperationContext to see if that helps by doing something like the following:

MessageBuffer buffer = OperationContext.Current.RequestContext.RequestMessage.CreateBufferedCopy(int.MaxValue);

Message message = buffer.CreateMessage();
using (XmlDictionaryReader reader = message.GetReaderAtBodyContents())
{
   string content = reader.ReadContentAsString();
}

However, I keep getting "This message cannot support the operation because it has been copied" as I assume the message has been copied previously somewhere by the framework? Anyway, I am now at a loss as to how to achieve the functionality required. Does anyone have any suggestions?

Thanks in advance

Upvotes: 0

Views: 1282

Answers (1)

Maurice
Maurice

Reputation: 27632

OperationContext.Current.RequestContext.RequestMessage points to the actual message so you can just use that.

Upvotes: 1

Related Questions