WebContentFormat.Raw in your WCF config file

If you want to specify WebContentFormat.Raw in your WCF service - so that it can process any content-type, but want that to happen from the config file and not programatically, here is one approach.


1) Add an overridden WebContentTypeMapper in your code, like this:


using System;

using System.ServiceModel.Channels;


namespace ebMS3.ServiceModel


    public class RawContentTypeMapper : WebContentTypeMapper


        public override WebContentFormat

                GetMessageFormatForContentType(string contentType)


            return WebContentFormat.Raw;





2) Reference this new WebContentTypeMapper in your config file in a customBinding:




    <binding name="RawReceiveCapable">

      <!-- Provide the fully qualified name of the WebContentTypeMapper  -->

      <webMessageEncoding webContentTypeMapperType=

          "ebMS3.ServiceModel.RawContentTypeMapper, ebMS3.ServiceModel,

                  Version=, Culture=neutral, PublicKeyToken=null" />

      <httpTransport manualAddressing="true" maxReceivedMessageSize="524288000"

            transferMode="Streamed" />

      <!-- maxReceivedMessageSize is 500 Mb -->





3) Finally, use the new customBinding on your endpoint, also in your config file:


<endpoint contract="MyContract" behaviorConfiguration="MyEndpointBehavior"

binding="customBinding" bindingConfiguration="RawReceiveCapable" />

That's it, another job done...