I have the following code in a message inspector to examine the response body. I understand the WCF Message can only be read once so I create a copy first. But with the following code I still get the error “This message cannot support the operation because it has been read.”…Am I missing something?
MessageBuffer buffer = message.CreateBufferedCopy(Int32.MaxValue);
Message copy = buffer.CreateMessage();
message = copy;
XmlDictionaryReader bodyReader = copy.GetReaderAtBodyContents();
bodyReader.ReadStartElement("Binary");
byte[] bodyBytes = bodyReader.ReadContentAsBase64();
string messageBody = Encoding.UTF8.GetString(bodyBytes);
return messageBody;
Also I don’t feel comfortable using Int23.MaxValue there. What would be a reasonable size?
Try this code: