Пример #1
0
        public static Message DecompressMessage(Message toDecompress, out CompressionMessageHeader compressionHeader)
        {
            compressionHeader = null;

            int index =
                toDecompress.Headers.FindHeader(WSCompressionStrings.Compression,
                                                WSCompressionStrings.NamespaceUri);
            if (index == -1)
                return toDecompress;

            using (XmlReader reader = toDecompress.Headers.GetReaderAtHeader(index))
            {
                compressionHeader = CompressionMessageHeader.ReadFrom(reader);
            }

            toDecompress.Headers.RemoveAll(WSCompressionStrings.Compression,
                                           WSCompressionStrings.NamespaceUri);

            string newMessageXml = DecompressMessageBody(toDecompress, compressionHeader);

            //Do not close the toDecompress message here, the framework manages its lifecycle.
            return CopyMessageAndReplaceContent(toDecompress, newMessageXml);
        }
Пример #2
0
        private static string DecompressMessageBody(Message toDecompress,
                                                         CompressionMessageHeader compressionHeader)
        {
            byte[] compressedData = ReadCompressedBody(toDecompress);

            byte[] data =
                DataCompressor.Decompress(compressedData, compressionHeader.Algorithm, compressionHeader.Level);

            return Encoding.UTF8.GetString(data);
        }