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 ‘http://weblogs.shockbyte.com.ar/rodolfof/compression/2006/02’ 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.

    Thanks.

      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 ‘http://tempuri.org/’. Found node type ‘Element’ with name ‘sc:CompressedData’ and namespace ‘http://weblogs.shockbyte.com.ar/rodolfof/compression/2006/02’

        Could you advise this?

        Thanks

      2. Hi Rodolfo,

        Here you go.

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

        // Close the original message
        message.Close();
        newMsg.Close();

        message = buffer.CreateMessage();
        buffer.Close();
        }

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

        string compressedBodyUri = WcfCompressionReferenceList.GenerateNewReference();
        compressionContent.ReferenceList.AddReference(compressedBodyUri);

        var document = new XmlDocument();

        document.Load(message.GetReaderAtBodyContents());

        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
        newMsg.Headers.CopyHeadersFrom(message);

        newMsg.Properties.CopyProperties(message.Properties);

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

        return newMsg;
        }

        //Contracts
        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?

        Thanks

Leave a Reply