WS-Compression for WSE 3

I had received some mails asking me for a version of WS-Compression for WSE 3, and here is finally!
The code includes a complete example of use.

7 thoughts on “WS-Compression for WSE 3”

  1. Rodolfo,

    I am having trouble connecting a WCF service to a ASMX service. I’ve created a custom binding in the WCF service:

    The error I get is:

    The header ‘Compression’ from the namespace ‘’ was not understood by the recipient of this message, causing the message to not be processed. This error typically indicates that the sender of this message has enabled a communication …

    Which lead me to this site. Any ideas on how I can correct my binding to communicate with the ASMX service?

    The developer of the original ASMX service has long since left the company.
    Your help would be greatly appreciated.


      1. Hi Rodolfo,

        I followed your example and getting the Error as below

        OperationFormatter encountered an invalid Message body. Expected to find node type ‘Element’ with name ‘GetLocaleStringResourceResponse’ and namespace ‘’. Found node type ‘Element’ with name ‘sc:CompressedData’ and namespace ‘’

        Could you advise this?


      2. Hi Rodolfo,

        Here you go.

        public void OnSend(ref Message message)
        Message newMsg = Compress(message);
        MessageBuffer buffer = newMsg.CreateBufferedCopy(int.MaxValue);

        // Close the original message

        message = buffer.CreateMessage();

        public Message Compress(Message message)
        var compressionContent = new WcfCompressionHeaderContent(Level);

        string compressedBodyUri = WcfCompressionReferenceList.GenerateNewReference();

        var document = new XmlDocument();


        XmlNode body = document.FirstChild;

        var compressedData = new WcfCompressionCompressedData(compressionContent.Level, encryptionKey, compressedBodyUri);
        MemoryStream compressedStream = compressedData.GetCompressedStream(body);

        // Create new message
        var xmlReader = new XmlTextReader(compressedStream);

        Message newMsg = Message.CreateMessage(message.Version, null, xmlReader);

        // Preserve the headers of the original message


        var compressionHeader = new MessageHeader(compressionContent, true, “”, false);
        newMsg.Headers.Add(compressionHeader.GetUntypedHeader(WcfCompressionValue.ElementNames.Compression, WcfCompressionValue.NamespaceURI));

        return newMsg;

        namespace Test.LocalizationFacade.Contracts
        [ServiceContract, ServiceKnownType(typeof(List)), ServiceKnownType(typeof(List))]
        public interface ILocalizationBF
        [FaultContract(typeof(WcfFaultContract)), OperationContract]
        LocalizationEntityWrapper GetLocaleStringResource(ParamLocaleStringResourceEntity paramEntity);

        namespace Test.EntityObjectWrapper
        public class LocalizationEntityWrapper
        public EntityWrapper Items { set; get; }

        public LocalizationEntityWrapper()
        Items = new EntityWrapper { new List(), new List() };

        public List LocaleStringResourceItem()
        if (Items == null)
        return null;

        return (List)Items[0];

        public List LanguageEntityItem()
        if (Items == null)
        return null;

        return (List)Items[1];

      3. I’m trying and I can not reproduce the error. You could send me by mail a test project which the complete code (your client code included) that is falling? Thks!

      4. Hi rodolfo,
        Can you PM me your email address?


Leave a Reply