I am transferring large chunks of data over WCF, and I am trying to optimize the results sent. I have switched from NetDataContactSerializer to DataContractSerializer, but since it is no longer being serialized as XML, I wonder exactly what happens.
As an example, imagine I serialize a collection (100,000 records) of the following to XML:
public class SomeDataObject
{
public string AnExcessivelyLongPropertyNameJustToIllustrateMyPoint { get; set; }
}
It would look something like this:
<a:SomeDataObject>
<b:AnExcessivelyLongPropertyNameJustToIllustrateMyPoint>
ABC
</b:AnExcessivelyLongPropertyNameJustToIllustrateMyPoint>
</a:SomeDataObject>
Now, from the above, it is clear that for hundreds of thousands of records, there is a significant performance gain in naming the property something else, like this:
<a:SomeDataObject>
<b:NormalName>ABC</b:NormalName>
</a:SomeDataObject>
My question is: When using a netTcp binding and the default DataContactSerializer, is it intelligent enough to not actually repeat the names of the properties being serialized?
Or if you don't know the answer to this, is there an easy way to measure this?
For WPF serialization to have smaller XML add short name in Name
attribute like:
[DataContract(Name="sdo")]
public class SomeDataObject
{
[DataMember(Name = "axlpnjtimp")]
public string AnExcessivelyLongPropertyNameJustToIllustrateMyPoint { get; set; }
}
For manual XML serialization using XmlSerializer
add attribute [XmlType(TypeName = "x")]
for class and [XmlElement("y")]
for properties.
In your case I would so something like:
[XmlType(TypeName = "sdo")]
public class SomeDataObject
{
[XmlElement("axlpnjtimp")]
public string AnExcessivelyLongPropertyNameJustToIllustrateMyPoint { get; set; }
}
And serialized xml:
<?xml version="1.0" encoding="utf-16"?>
<sdo>
<axlpnjtimp>Property Name</axlpnjtimp>
</sdo>
It will reduce send data size considerably.