One of the tasks on my todo list has been to switch our Silverlight project at work from basicHttpBindings in WCF to the new Binary Binding – which should hopefully reduce network traffic, improve security etc etc.

I was kind of dreading this task, expecting it to be truly awkward, but in actual fact it was a piece of cake.

Two major steps:

1. Update the web.config file for the service, replacing the binding details with the new structure detailing the binary binding, and changing the endpoint. For example:

The original binding had:

<basicHttpBinding>
    <binding name="Application.Binding">
        <security mode="Transport">
            <transport clientCredentialType="None" proxyCredentialType="None" realm="" />
        </security>
    </binding>
</basicHttpBinding>

With the endpoint defined:

<endpoint address="" binding="basicHttpBinding" contract="Application.IApplication" bindingConfiguration="Application.Binding">
    <identity>
        <dns value="localhost"/>
    </identity>
</endpoint>

To switch this to binary binding, simply add:

<customBinding>
    <binding name="Application.BinaryBinding">
        <binaryMessageEncoding />
        <httpsTransport />
    </binding>
</customBinding>

And use this new binding as follows

<endpoint address="" binding="customBinding" contract="Application.IApplication" bindingConfiguration="Application.BinaryBinding">
</endpoint>

Note that both of these binding definitions are running on SSL; if you wanted to run the binary binding on http, simply drop the “s” from the line <httpsTransport />.

2. Refresh the service references in Visual Studio.

Thats it!