How to compress WCF traffic hosted on ServiceBus using NetTcpRelay binding

729 Views Asked by At

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?

1

There are 1 best solutions below

1
On

Try this:

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

How to get gzip compression working in WCF 4.5