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.

About Rodolfo Finochietti

Uma's and Gino's father, and a programmer ;)

Posted on 02/07/2006, in Tools, Web Services. Bookmark the permalink. 7 Comments.

  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.


    • Hi Jhon,

      To enable WS-Compresión you need to configue the filter in both sides: the client and the server. You can see a example in the code published here:…ession-for-wcf/

      Unfortunately the WS-Compression bindings is not compatible with ASM programming model.

      • 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?


      • Hi,

        You can send me the code that is failing?


      • 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];

      • 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!

      • Hi rodolfo,
        Can you PM me your email address?


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: