创建WCF消息的缓冲副本 [英] Create a buffered copy of WCF Message

查看:142
本文介绍了创建WCF消息的缓冲副本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个消息检查下面的代码检查响应主体。我明白,所以我先创建一个副本WCF消息只能被读取一次。但是,下面的代码我仍然得到错误,因为它已被阅读此消息不支持操作。......我失去的东西吗?

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;



此外,我不使用Int23.MaxValue那里感觉很舒服。这将是一个合理的规模。

Also I don't feel comfortable using Int23.MaxValue there. What would be a reasonable size?

推荐答案

试试这个代码:

    MessageBuffer buffer = message.CreateBufferedCopy(Int32.MaxValue);
    message = buffer.CreateMessage();

    var copy = buffer.CreateMessage();
    XmlDictionaryReader bodyReader = copy.GetReaderAtBodyContents();
    bodyReader.ReadStartElement("Binary");
    byte[] bodyBytes = bodyReader.ReadContentAsBase64();
    string messageBody = Encoding.UTF8.GetString(bodyBytes);

    return messageBody;

这篇关于创建WCF消息的缓冲副本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆