0

We want to use GZip compression on our WCF 4.5 service. We are hosting the service on ServiceBus and are using the NetTcpRelayBinding.

WCF 4.5 should support GZip compression OOB. I've extended the standard NetTcpRelayBinding and turned on GZip compression

    public class CompressedNetTcpRelayBinding : NetTcpRelayBinding 
    {
        public override BindingElementCollection CreateBindingElements()
        {
            var elements = base.CreateBindingElements();
            var encodingBinding = elements.Single(e => e is BinaryMessageEncodingBindingElement);
            ((BinaryMessageEncodingBindingElement)encodingBinding).CompressionFormat = CompressionFormat.GZip;

            var bindingElementCollection = new BindingElementCollection();
            foreach (var bindingElement in elements)
            {
                bindingElementCollection.Add(bindingElement);
            }

            return bindingElementCollection.Clone();
        }
    }

However, when I try to host the service I get the following exception:

The transport configured on this binding does not appear to support the CompressionFormat specified (GZip) on the message encoder. To resolve this issue, set the CompressionFormat on the BinaryMessageEncodingBindingElement to 'None' or use a different transport.

NetTcpRelayBinding uses the default Microsoft.ServiceBus.TcpRelayTransportBindingElement.

What should I do in order to make this work?

mrBob
  • 385
  • 6
  • 22

1 Answers1

0

Try this:

<customBinding>
  <binding name="BinaryCompressionBinding"> 
    <binaryMessageEncoding compressionFormat="GZip"/> 
    <httpTransport /> 
  </binding>
</customBinding>

How to get gzip compression working in WCF 4.5

Community
  • 1
  • 1
Musfiqur rahman
  • 749
  • 4
  • 12
  • If you take a look at the code, you'll see that's exactly what I tried to do, but it seems that it doesn't work with NetTcpRelay binding. – mrBob Dec 19 '13 at 23:08