WCF 消息正文显示 <s:Body>... 流 ...</s:Body>修改后 [英] WCF message body showing <s:Body>... stream ...</s:Body> after modification

查看:40
本文介绍了WCF 消息正文显示 <s:Body>... 流 ...</s:Body>修改后的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试使用MessageInspector通过代理修改wcf服务之前的消息.但是,在调试消息正文时不会被复制并且正文显示

Trying to use MessageInspector to modify the message before the wcf service through the proxy. However while debugging the message body does not gets copied and body shows

 <s:Body>... stream ...</s:Body>

代码有什么问题?

public class CustomWCFMessageInspector : IClientMessageInspector
{
    public object BeforeSendRequest(ref Message request, IClientChannel channel)
    {
        request = ModifyMessage(request);
        return null;
    }

    private Message ModifyMessage(Message oldMessage)
    {
        Message newMessage = null;
        MessageBuffer msgbuf = oldMessage.CreateBufferedCopy(int.MaxValue);

        Message tmpMessage = msgbuf.CreateMessage();
        XmlDictionaryReader xdr = tmpMessage.GetReaderAtBodyContents();

        XDocument xd = ConvertToXDocument(xdr);

        EmitTags(xd);

        var ms = new MemoryStream();
        var xw = XmlWriter.Create(ms);
        xd.Save(xw);

        xw.Flush();
        xw.Close();

        ms.Position = 0;
        XmlReader xr = XmlReader.Create(ms);

        newMessage = Message.CreateMessage(tmpMessage.Version, null, xr);
        newMessage.Headers.CopyHeadersFrom(tmpMessage);
        newMessage.Properties.CopyProperties(tmpMessage.Properties);

        return newMessage;
    }

}

推荐答案

问题是在做ToString()后newMessage body没有显示在watch窗口中

The problem was that the newMessage body was not shown in the watch window after doing ToString()

创建了要在调试器中显示的消息的缓冲副本.

Created the buffered copy of the message to be shown in the debugger.

MessageBuffer messageBuffer = newMessage.CreateBufferedCopy(int.MaxValue);
Message message = messageBuffer.CreateMessage();

所以代码中没问题.只是调试器没有显示下面链接中提到的消息正文

So there is No problem in the code. It is just that the debugger is not showing the message body as mentioned in the link below

http://msdn.microsoft.com/en-us/library/ms734675(v=VS.90).aspx

访问消息正文进行调试部分.

这篇关于WCF 消息正文显示 &lt;s:Body&gt;... 流 ...&lt;/s:Body&gt;修改后的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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