title: Predefine XML namespaces for DataContractSerializer
body: <p>I'm building a self hosted WCF service. I'm building a special data structure for a very flexible transport of data. So far I test if my structure is serializable using the DataContractSerializer. That works fine and I'm happy about that, but there is something annoying me:</p>
  
  <p>In my XML output are dozens redefined xmlns attributes e.g.:</p>
  
  <pre><code>xmlns:a="http://schemas.microsoft.com/2003/10/Serialization/Arrays"
  xmlns:b="http://www.w3.org/2001/XMLSchema"
  </code></pre>
  
  <p>This should be better defined once in the root element so that bytes could be simply optimized. Is there a way to add custom namespace informations to the root element?</p>
  
  <p>Here is a bigger example to demonstrate what I mean:</p>
  
  <pre><code>&lt;DataObject xmlns="http://schemas.datacontract.org/2004/07/Test"
              xmlns:i="http://www.w3.org/2001/XMLSchema-instance"&gt;
    &lt;Data xmlns:a="http://schemas.microsoft.com/2003/10/Serialization/Arrays"&gt;
      &lt;a:KeyValueOfstringanyType&gt;
        &lt;a:Key&gt;ID&lt;/a:Key&gt;
        &lt;a:Value i:type="b:int" xmlns:b="http://www.w3.org/2001/XMLSchema"&gt;1&lt;/a:Value&gt;
      &lt;/a:KeyValueOfstringanyType&gt;
      &lt;a:KeyValueOfstringanyType&gt;
        &lt;a:Key&gt;Value&lt;/a:Key&gt;
        &lt;a:Value i:type="b:int" xmlns:b="http://www.w3.org/2001/XMLSchema"&gt;42&lt;/a:Value&gt;
      &lt;/a:KeyValueOfstringanyType&gt;
    &lt;/Data&gt;
    &lt;Data xmlns:a="..."&gt;...&lt;/Data&gt;
    &lt;Data xmlns:a="..."&gt;...&lt;/Data&gt;
    &lt;Data xmlns:a="..."&gt;...&lt;/Data&gt;
  &lt;/DataObject&gt;
  </code></pre>
  
  <p>What I want is something like this:</p>
  
  <pre><code>&lt;DataObject xmlns="http://schemas.datacontract.org/2004/07/Test"
              xmlns:i="http://www.w3.org/2001/XMLSchema-instance"
              xmlns:a="http://schemas.microsoft.com/2003/10/Serialization/Arrays"
              xmlns:b="http://www.w3.org/2001/XMLSchema"&gt;
    &lt;Data&gt;
      &lt;a:KeyValueOfstringanyType&gt;
        &lt;a:Key&gt;ID&lt;/a:Key&gt;
        &lt;a:Value i:type="b:int"&gt;1&lt;/a:Value&gt;
      &lt;/a:KeyValueOfstringanyType&gt;
      &lt;a:KeyValueOfstringanyType&gt;
        &lt;a:Key&gt;Value&lt;/a:Key&gt;
        &lt;a:Value i:type="b:int"&gt;42&lt;/a:Value&gt;
      &lt;/a:KeyValueOfstringanyType&gt;
    &lt;/Data&gt;
    &lt;Data&gt;...&lt;/Data&gt;
    &lt;Data&gt;...&lt;/Data&gt;
    &lt;Data&gt;...&lt;/Data&gt;
  &lt;/DataObject&gt;
  </code></pre>