We have noted that WCF DataContractSerializer isn't very efficient when it comes to serializing null
values during an SOAP call. For audit purposes, we also record the exact message as sent to disk, so this wastes storage. A typical message with more than one nil element is sent like so:
<MyMessage xmlns="myXmlns">
<field0>1234567</field0>
<field1 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true" />
<field2 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true" />
<field3 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true" />
// etc
</MyMessage>
What would be an immeasurable improvement for bandwidth and disk considerations would be to generate a SOAP body such as:
<MyMessage xmlns="myXmlns" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<field0>1234567</field0>
<field1 xsi:nil="true" />
<field2 xsi:nil="true" />
<field3 xsi:nil="true" />
//etc
</MyMessage>
So my question is, how can I change my WCF client to consolidate the XSI namespace on the root element, to prevent it from being repeated on each nil element?