30 March 2014

Compress the Binary Encoder message


Begging from WCF 4.5 onward, WCF binary message encoder supports message compression. Type of compression can be mention in the binding settings

Points to remember:

Both the client and the service must configure the CompressionFormat property, if service is configured with compression and client is not configured then system will throw exception.
Compression will work for HTTP, HTTPS and TCP protocol

You need to create the custom binding to use this feature

Compression is mostly useful if network bandwidth is a bottleneck. In the case where the CPU is the bottleneck, compression will decrease throughput.

    <custom Binding>
        <binding name="BinaryCompressionBinding">
          <binaryMessageEncoding compression Format ="GZip"/>
           <http Transport />
         </binding>
      </custom Binding>

Channel Factor Caching

In some client application Channel Factory is used to create a communication between Client and Service. Creating ChannelFactor will increase the overhead by following operation.

Constructing the Contract Description tree

Reflecting all of the required CLR types

Constructing the channel stack

Disposing of resources

In order to avoid this overhead, WCF 4.5 introduced the caching mechanism for ChannelFactor.
Caching will take three types of values

CacheSetting.AlwaysOn - All instances of Client Base within the app-domain can participate in caching

CacheSetting.AlwaysOff - Caching is turned off for all instances of Client Base

CacheSetting.Default - Only instances of Client Base created from endpoints defined in configuration files participate in caching within the app-domain

    Client Base < IService>.CacheSetting = CacheSetting.AlwaysOn;
            Foreach (string id in lstEmpIds)
            {
                Using (Test Client proxy = new Test Client(new BasicHttpBinding(),
                                                     new Endpoint Address(address)))
                {
                    // ...
                    proxy.GetEmployeeDetails (id);
                    // ...
                }
            }

No comments:

Post a Comment