【问题标题】:How get body of message in wcf inspector如何在 wcf 检查器中获取消息正文
【发布时间】:2012-09-09 22:19:41
【问题描述】:

我需要监控服务的响应,我用方法GetReaderAtBodyContents()得到body,但是当WCF发送错误消息时,body无法读取,因为消息没有xmlelement("Text cannot be written outside the root element.")?我看到那个文本不能有<binary>。谁知道有得到错误消息的正文?

【问题讨论】:

    标签: wcf text inspector


    【解决方案1】:

    【讨论】:

    • wcf 返回回复.IsFault = false
    【解决方案2】:

    消息格式为 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>,如何解决?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-12-15
      • 1970-01-01
      • 2011-06-03
      • 1970-01-01
      相关资源
      最近更新 更多