GZipMessageEncoder net.Tcp Binding RRS feed

  • Question

  • Hi,

    I am trying to get the technology sample "Compression" with the GZipMessageEncoder ready to support Net.TcpBinding. Everything works as expected despite the streaming stuff:

    I do not really understand what's wrong with the two methods of the custom GZipMessageEncoder here:

                public override Message ReadMessage(System.IO.Stream stream, int maxSizeOfHeaders, string contentType)
                    //Pass false for the "leaveOpen" parameter to the GZipStream constructor.
                    //This will ensure that the inner stream gets closed when the message gets closed, which
                    //will ensure that resources are available for reuse/release.
                    GZipStream gzStream = new GZipStream(stream, CompressionMode.Decompress, false);
                    return innerEncoder.ReadMessage(gzStream, maxSizeOfHeaders);

                public override void WriteMessage(Message message, System.IO.Stream stream)
                    using (GZipStream gzStream = new GZipStream(stream, CompressionMode.Compress, true))
                        innerEncoder.WriteMessage(message, gzStream);

                    // innerEncoder.WriteMessage(message, gzStream) depends on that it can flush data by flushing
                    // the stream passed in, but the implementation of GZipStream.Flush will not flush underlying
                    // stream, so we need to flush here.

    Does anybody tried this with Net.TcpBinding and transfer mode set to "Streamed"?


    Wednesday, February 22, 2017 4:33 PM

All replies

  • Hi Markus,

    Could you share us more description of your issue? After changing to Streamed, what is the unexpected result? Did it cause out of memory or any other issue?

    Based on your code, it is the same as MS WCF GZIP sample. If you are confused about memory cause, I suggest you check whether below link is helpful.

    # WCF HttpTransport: streamed vs buffered TransferMode

    Best Regards,


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact

    Thursday, February 23, 2017 2:29 AM