我需要监控服务的响应,我用方法获取正文GetReaderAtBodyContents()
,但是当 WCF 发送错误消息时,正文无法读取,因为消息没有xmlelement("Text cannot be written outside the root element.")
?我看到那个文本不能有<binary>
。谁知道有得到错误信息的正文?
问问题
1576 次
2 回答
1
消息格式为 RAW,我阅读正文:
var bodyReader = message.GetReaderAtBodyContents();
bodyReader.ReadStartElement("Binary");
var bodyBytes = bodyReader.ReadContentAsBase64();
writer = XmlDictionaryWriter.CreateBinaryWriter(ms);
writer.WriteStartElement("Binary");
writer.WriteBase64(bodyBytes, 0, bodyBytes.Length);
writer.WriteEndElement();
writer.Flush();
ms.Position = 0;
reader = XmlDictionaryReader.CreateBinaryReader(ms, XmlDictionaryReaderQuotas.Max);
body = Encoding.UTF8.GetString(bodyBytes);
ms.Position = 0;
newMessage = Message.CreateMessage(reader, int.MaxValue, message.Version);
CopyMessagePropertiesAndHeaders(message, newMessage);
message = newMessage;
但是如果返回错误消息,GetReaderAtBodyContents() 会引发错误,因为消息没有 xmlelement <Binary>
,如何解决?
于 2012-09-18T08:33:55.487 回答
0
于 2012-09-17T16:54:42.987 回答