Silverlight 3 WCF Binary Message Encoding

October 14, 2009 08:29 by wjchristenson2

Silverlight 3 offers us some new features when it comes to WCF web services.  In Silverlight 2, BasicHttpBinding was the only supported binding.  This essentially encodes your serialized objects in clear text and sends them over an HTTP transport.  Because the objects were sent as clear text, the message size could get out-of-hand.  When sending data across HTTP/Internet, you obviously want to decrease the size as this will improve performance of your client application.  Silverlight 3 offers the ability to create custom bindings which support the ability to encode your WCF web service messages as a binary format.

Binary encoding offers some serious performance gains over text encoding.  Personally I’ve seen 30% – 40% reduction in message size between the server and client when binary encoding is enabled.  Keep in mind that binary encoding is a WCF-specific feature.  Therefore if you have heterogeneous technologies wanting to consume your service, you’ll need to stick with BasicHttpBinding.  Here is an example of how to enable binary encoding for your WCF service:


<bindings>
	<customBinding>
		<binding name="binaryHttpBinding">
			<binaryMessageEncoding />
			<httpTransport />
		</binding>
	</customBinding>
</bindings>
   
<endpoint address="" binding="customBinding" bindingConfiguration="binaryHttpBinding" contract="MyService" />
Bookmark and Share