Transmitting the least amount of data over the wire with WCF

前端 未结 4 600
迷失自我
迷失自我 2021-01-03 14:56

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



    

        
相关标签:
4条回答
  • 2021-01-03 15:35

    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
    0 讨论(0)
  • 2021-01-03 15:43

    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.

    0 讨论(0)
  • 2021-01-03 15:45
    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.

    0 讨论(0)
  • 2021-01-03 15:57

    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.

    0 讨论(0)
提交回复
热议问题