IClientMessageInspector.AfterReceiveReply只写“... datastream ...”

时间:2012-08-06 13:25:24

标签: .net wcf

我有一个简单的IClientMessageInspector:

public class ConsoleMessageTracer : IClientMessageInspector
{
    public void AfterReceiveReply(ref Message reply, object correlationState)
    {
        Console.WriteLine(reply.ToString());
    }

    public object BeforeSendRequest(ref Message request, IClientChannel channel)
    {
        Console.WriteLine(request.ToString());
    }
}

AfterReceiveReply工作正常,但只在BeforeSendRequest ... Datastream ...  写入控制台。

(实际上它写... Datenstrom ...,因为我有.Net的德语安装,Thread.CurrentThread.CurrentCulture似乎被忽略了。)

如何访问请求消息的实际正文?

2 个答案:

答案 0 :(得分:1)

您需要阅读流以获取整个消息。但是,您还需要确保以允许在之后读取/写入消息的方式执行此操作。有关如何实现此目的的详细信息,请参阅this explanation

答案 1 :(得分:0)

您好,您可以尝试使用此代码 - InputStream

    string documentContents = string.Empty;
    using (Stream receiveStream = Request.InputStream)
    {
        using (StreamReader readStream = new StreamReader(receiveStream, Encoding.UTF8))
        {
            documentContents = readStream.ReadToEnd();
        }
    }