# Wednesday, May 21, 2008

WCF serialization and RemotingFormat

Anyone familiar with building applications using .NET Remoting (in .NET 2.0) knows that the DataSet and DataTable classes have a property called RemotingFormat. This could be set to either XML or Binary where Binary would give you a performance boost since it is more compact.

Windows Communication Foundation does not use this property at all. The service binding dictates the serialization format, no matter what you set the RemotingFormat property to be, even if your using a NetHttpBinding.

The following configuration will setup a service to use .NET Binary formatting over Http:

<system.serviceModel>
  <bindings>
    <customBinding>
      <binding name="NetHttpBinding">
        <reliableSession />
        <compositeDuplex />
        <oneWay  />
        <binaryMessageEncoding  />
        <httpTransport />
      </binding>
    </customBinding>
  </bindings>
  <services>
    <service behaviorConfiguration="ServiceBehavior" name="MyService">
      <endpoint address="" binding="customBinding"
        bindingConfiguration="NetHttpBinding" name="HttpBinding" contract="IService" />
      <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
    </service>
  </services>
  <behaviors>
    <serviceBehaviors>
      <behavior name="ServiceBehavior">
        <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
        <serviceMetadata httpGetEnabled="true"/>
        <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
        <serviceDebug includeExceptionDetailInFaults="false"/>
      </behavior>
    </serviceBehaviors>
  </behaviors>
</system.serviceModel>

So even if your service looks something like this:

public DataSet GetData()
{
    DataSet ds = BuildDataSet();   // retrieve some data here
    ds.RemotingFormat = SerializationFormat.Xml;
    return ds;
}

The DataSet will still get serialized as a .NET binary as defined in the binding ('binaryMessageEncoding').

#    Comments [0] |