Text Versus Binary Encoding

Prior to WCF, you had a number of choices for building distributed applications. Two of those options were .NET Remoting and ASP.NET Web Services. .NET Remoting was great for communicating between .NET applications because it optimized the transmission of data using binary encoding. This offered better performance than ASP.NET Web Services, which leveraged text encoding for interoperability. Text encoding was acceptable for ASP.NET Web Services because it allowed for interoperability across platforms. WCF abstracts out the encoding mechanism and allows for bindings that allow for both styles of encoding. This allows WCF to provide functionality that replaces both .NET Remoting and ASP.NET Web Services.

Encoding is not something that you work with directly. Instead, it is specified by the binding used to expose a service. Chapter 4, "Bindings," highlighted bindings for use between .NET applications and those used for interoperability. The netTcpBinding binding, which is used between .NET applications, leverages the binaryMessageEncoding encoder. The binaryMessageEncoding encoder offers the best performance, but it does not support interoperability. Conversely, bindings such as the wsHttpBind-ing binding use the textMessageEncoding encoder, which offers interoperability using the WS-* specifications. Listing 6.34 shows an example of a custom binding using the textMessageEncoding encoder.

Listing 6.34 Custom Binding Using textMessageEncoding

<?xml version="1.0" encoding="utf-8" ?> <configuration>

<system.serviceModel> <bindings>

<customBinding>

<binding name="Custom">

<textMessageEncoding /> <httpTransport /> </binding> </customBinding> </bindings> <client>

<endpoint address="http://localhost/SerializationExample/Service.svc"

binding="customBinding"

bindingConfiguration="Custom"

contract="Serialization.localhost.IEmployeeInformation" name="IEmployeeInformation" /> </client> </system.serviceModel> </configuration>

Listing 6.35 shows the configuration of a custom binding using the binaryMessageEncoding encoder.

Listing 6.35 Custom Binding Using binaryMessageEncoding

<?xml version="1.0" encoding="utf-8" ?> <configuration>

<system.serviceModel> <bindings>

<customBinding>

<binding name="Custom">

<binaryMessageEncoding /> <httpTransport /> </binding> </customBinding> </bindings> <client>

<endpoint address="http://localhost/SerializationExample/Service.svc"

binding="customBinding"

bindingConfiguration="Custom"

contract="Serialization.localhost.IEmployeeInformation" name="IEmployeeInformation" /> </client> </system.serviceModel> </configuration>

+1 0

Post a comment