自己ホスト型の WCF サービスを構築しています。非常に柔軟なデータ転送のための特別なデータ構造を構築しています。これまでのところ、DataContractSerializer を使用して構造がシリアライズ可能かどうかをテストしました。それはうまく機能し、私はそれについて満足していますが、私を悩ませる何かがあります:
私の XML 出力には、再定義された多数の xmlns 属性があります。
xmlns:a="http://schemas.microsoft.com/2003/10/Serialization/Arrays"
xmlns:b="http://www.w3.org/2001/XMLSchema"
これは、バイトを簡単に最適化できるように、ルート要素で一度定義することをお勧めします。カスタム名前空間情報をルート要素に追加する方法はありますか?
これは、私が何を意味するかを示すためのより大きな例です。
<DataObject xmlns="http://schemas.datacontract.org/2004/07/Test"
xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<Data xmlns:a="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
<a:KeyValueOfstringanyType>
<a:Key>ID</a:Key>
<a:Value i:type="b:int" xmlns:b="http://www.w3.org/2001/XMLSchema">1</a:Value>
</a:KeyValueOfstringanyType>
<a:KeyValueOfstringanyType>
<a:Key>Value</a:Key>
<a:Value i:type="b:int" xmlns:b="http://www.w3.org/2001/XMLSchema">42</a:Value>
</a:KeyValueOfstringanyType>
</Data>
<Data xmlns:a="...">...</Data>
<Data xmlns:a="...">...</Data>
<Data xmlns:a="...">...</Data>
</DataObject>
私が欲しいのは次のようなものです:
<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">
<Data>
<a:KeyValueOfstringanyType>
<a:Key>ID</a:Key>
<a:Value i:type="b:int">1</a:Value>
</a:KeyValueOfstringanyType>
<a:KeyValueOfstringanyType>
<a:Key>Value</a:Key>
<a:Value i:type="b:int">42</a:Value>
</a:KeyValueOfstringanyType>
</Data>
<Data>...</Data>
<Data>...</Data>
<Data>...</Data>
</DataObject>