1

My project has a netTCP WCF service. This is the app.config for it:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <system.serviceModel>
        <bindings>
            <netTcpBinding>
                <binding name="NetTcpBinding_IIndexer" closeTimeout="00:01:00"
                    openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
                    transactionFlow="false" transferMode="Buffered" transactionProtocol="OleTransactions"
                    hostNameComparisonMode="StrongWildcard" listenBacklog="10"
                    maxBufferPoolSize="524288" maxBufferSize="65536" maxConnections="10"
                    maxReceivedMessageSize="65536">
                    <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
                        maxBytesPerRead="4096" maxNameTableCharCount="16384" />
                    <reliableSession ordered="true" inactivityTimeout="00:10:00"
                        enabled="false" />
                    <security mode="None">
                        <transport clientCredentialType="Windows" protectionLevel="EncryptAndSign" />
                        <message clientCredentialType="Windows" />
                    </security>
                </binding>
            </netTcpBinding>
        </bindings>
        <client>
            <endpoint address="net.tcp://mach1:9000/Indexer" binding="netTcpBinding"
                bindingConfiguration="NetTcpBinding_IIndexer" contract="in.IIndexer"
                name="NetTcpBinding_IIndexer" />
        </client>
    </system.serviceModel>
</configuration>

Is there any thing that can be done to maximize the compression of the data being sent over the wire? My project is internal so speed and processing power are essentially of no issue.

What are some good tips and tricks to compress the data sent from the client to the WCF service?

Matt Davis
  • 45,297
  • 16
  • 93
  • 124
Matt
  • 25,943
  • 66
  • 198
  • 303

4 Answers4

8

The message encoding specified by the binding will determine how your data gets turned into bytes on the wire. For the NetTcpBinding, it will automatically use binary encoding which gives you the most compact representation of your message out of all the built-in WCF encoders.

For more information, I would recommend these resources:

  1. Zulfiqar Ahmed: SOAP message size optimization: Encoding vs compression
  2. Kenny Wolf: Performance Characteristics of WCF Encoders
  3. MSDN: Choosing a Message Encoder
Iúri dos Anjos
  • 371
  • 4
  • 20
bobbymcr
  • 23,769
  • 3
  • 56
  • 67
2

It depends upon the sort of data that you're sending, but if you're using serialization to create the data, then serializing to XML and compressing that with a GZipStream can result in fewer bytes than compressing the data generated by a binary serialization.

John Fisher
  • 22,355
  • 2
  • 39
  • 64
  • So this is where I get confused -- I haven't set up any serialization, I'm either transmitting primitives or an array of a custom class. The custom class doesn't inherit ISerializable nor is it marked with the [Serialized] attribute. All I have done is mark all of my custom class' public properties with the [datamember] attribute. Other than that, nothing else has been done. So I don't really know what I have. :-( – Matt Aug 28 '09 at 14:50
  • Oh. Then, you're not really controlling what's transported. You can look into the WCF stream controls to see what compresion you could add (I haven't done this). Or, you can stop transporting the actual objects, and change your contracts to transport compressed blobs which are converted to or from the actual objects. – John Fisher Aug 28 '09 at 16:25
  • 1
    Based on the difficulty of finding information about WCF compression over TCP and on the existence of a compression feature in http://www.noemax.com/products/wcfx/features.html, I suspect that you're going to need to write code, or purchase a third-party compression capability. – John Fisher Aug 28 '09 at 16:43
2

I'm still trying to piece all of this together myself, but I do know that when you use the DataContractAttribute, you are using DataContract serialization. I'm not clear exactly on the differences between this serialization scheme and the Serializable scheme, but from what I've been able to gather, they are different.

Marc Gravell, one of the moderators here at SO, is the expert that I've looked to on this issue. He actually has a serialization scheme called protobuf-net that is available for use here.

Matt Davis
  • 45,297
  • 16
  • 93
  • 124
0
  1. Use compression .. In 4.5

      <binaryMessageEncoding compressionFormat="GZip"/>
    
      <tcpTransport maxReceivedMessageSize="20000000"/>
    </binding>
    

  2. Do not use namespaces set namespace to "" (and on the service contract as well.) [DataContract(Namespace = "" )] public class AddDeckMessage

  3. Rarely ( if ever send Interfaces / base classes on XML) ... XML does not understand and it adds Microsoft explcit XML. Do not use knowntype use plain DTOs which you can customize to the wire...

  4. Use EmitDefaultValue

  5. Be careful with byte[] with non tcp compression. If you see it as 123 your seeing 15-30 bytes for each byte depending on encoding. Use uuencode if you need to use standard WS protocols.

user1496062
  • 1,309
  • 1
  • 7
  • 22