Tuesday, April 27, 2010

Add binary serialization to a WCF webservice using UsernameOverTransport security

In order to enable this we have to add a new binding to our service and specify which endpoint to use. Add the following binding to the bindings section in the web.config on the service and client side:

<customBinding>

        <binding name="binaryHttpBinding">

          <security authenticationMode="UserNameOverTransport" requireSecurityContextCancellation="true" >

            <secureConversationBootstrap authenticationMode="UserNameForSslNegotiated" />

          </security>         

          <binaryMessageEncoding maxReadPoolSize="2147483647" maxSessionSize="2147483647" maxWritePoolSize="2147483647">

            <readerQuotas maxDepth="32" maxStringContentLength="5242880"

            maxArrayLength="200000" maxBytesPerRead="4096" maxNameTableCharCount="16384" />

          </binaryMessageEncoding>         

          <httpsTransport maxBufferPoolSize="2147483647" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647"></httpsTransport>         

        </binding>       

      </customBinding>

Specify an endpoint for it like this, and you are ready to go:

<endpoint address="" binding="customBinding" bindingConfiguration="binaryHttpBinding" contract="ServiceLibrary.MyService" />   

Hope this helps, I searched a while for the solution and it wasn't on the web.

Starting to love this WCF thingy :)