Least Cable Data Transfer Using WCF

My project has a netTCP WCF service. To do this, use app.config:

<?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 anything that can be done to maximize the compression of data sent over the wire? My project is internal, so speed and processing power are essentially not a problem.

What are some helpful tips and tricks for compressing data sent by the client to the WCF service?

+1
source share
4 answers

The message encoding indicated by the binding will determine how your data is converted into bytes per wire. For NetTcpBinding, it will automatically use binary encoding, which gives you the most compact representation of your message from all the built-in WCF codes.

For more information, I would recommend these resources:

+8
source

It depends on the data you send, but if you use serialization to create data, then serializing in XML and compressing with GZipStream can lead to a reduction in the number of bytes than compressing the data generated by binary serialization.

+2
source

I'm still trying to put it all together on my own, but I know that when you use a DataContractAttribute, you are using serialization of a DataContract. I do not quite understand the differences between this serialization scheme and the Serializable scheme, but from what I was able to assemble, they are different.

Mark Gravell, one of the moderators here at SO, is the expert I was looking for on this issue. It actually has a serialization scheme called protobuf-net, which is available for use here .
+2
source
  • Use compression .. In 4.5

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

  • Do not use the namespace for names in "(and in the service contract). [DataContract (namespace =" ")] public class AddDeckMessage

  • Rarely (if you ever send interfaces / base classes in XML) ... XML does not understand and adds Microsoft explcit XML. Do not use knowntype to use regular DTOs that you can configure to wire ...

  • Using EmitDefaultValue

  • Be careful with byte [] with compression without tcp. If you see that you see 15-30 bytes for each byte depending on the encoding. Use uuencode if you need to use standard WS protocols.

0
source

Source: https://habr.com/ru/post/1389993/


All Articles