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 ‘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.

    • 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: https://shockbyte.net/2006/04/06/new-version-of…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 ‘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

      • Hi,

        You can send me the code that is failing?

        Regards//

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

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

        Thanks

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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: