WCF Tutorial
www.Learn2Expert.net A new ASP.Net MVC 4, SSIS, Interview Q/A tutorial - Visit - www.Learn2Expert.net
Skip Navigation LinksHomeWhat's new in WCF 4.5What's new in WCF 4.5-Part 6 No of Views: 23684
WCF Tutorial | What's new in WCF 4.5 Part 6

What's new in WCF 4.5 - Part 6

Compress the Binary Encoder message

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

Points to remember:

  1. 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.
  2. Compression will work for HTTP, HTTPS and TCP protocol
  3. You need to create the custom binding to use this feature
  4. Compression is mostly useful if network bandwidth is a bottleneck. In the case where the CPU is the bottleneck, compression will decrease throughput.
    <customBinding> 
        <binding name="BinaryCompressionBinding"> 
          <binaryMessageEncoding compressionFormat ="GZip"/> 
           <httpTransport /> 
         </binding> 
      </customBinding>

ChannelFactory Caching

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

  1. Constructing the ContractDescription tree
  2. Reflecting all of the required CLR types
  3. Constructing the channel stack
  4. 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 ClientBase within the app-domain can participate in caching
  • CacheSetting.AlwaysOff - Caching is turned off for all instances of ClientBase
  • CacheSetting.Default - Only instances of ClientBase created from endpoints defined in configuration files participate in caching within the app-domain
    ClientBase < IService>.CacheSetting  = CacheSetting.AlwaysOn;
            foreach (string id in lstEmpIds)
            {
                using (TestClient proxy = new TestClient(new BasicHttpBinding(),
                                                     new EndpointAddress(address)))
                {
                    // ...
                    proxy.GetEmployeeDetails(id);
                    // ...
                }
            }

Tips!

  • Always create the service with Interface->Implementation format, mention the contract in Interface.
  • Define the service in Class library and refer the class library in Host project. Don’t use service class in host project.
  • Change the instance mode to per call as default.
  • Always catch exception using try/catch block and throw exception using FaultException < T >.
  • Logging and Include exception should be enable while compiling the project in debug mode. While in production deployment disable the logging and Include exception details.