私は自己ホストWCFサービスを構築しています。私は非常に柔軟なデータ転送のための特別なデータ構造を構築しています。これまでのところ、私は自分の構造体がDataContractSerializerを使ってシリアライズ可能かどうかをテストします。それは正常に動作し、私はそれについて満足しているが、何か迷惑な私にあります:私のXML出力で 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>
を(のhttp:/ /stackoverflow.com/questions/258960/how-to-serialize-an-object-to-xml-without-getting-xmlns)< - これはあなたが望むものを含んでいます –
@ MarkusJarderotは本当にありません。それは一般的な名前空間を取り除く方法のようです。 WCF契約にはそれが必要です(これまでのところ私が知っています)!私はちょうどseverialの再定義があることを避けたいと思う。 – rekire