(WCFを使用して)RESTAPIを介してかなり複雑なオブジェクトをXMLとして公開しようとしています。
ただし、オブジェクトはXSDファイルで定義されているため、xsd.exeツールを使用してクラスを生成しました。問題は、オブジェクトがXMLにシリアル化されると、属性(xsdで定義)が要素にシリアル化されるように見えることです。そして、私には理由がわかりません。現在、私のxsdはどういうわけかそれを許可していると思いますが、理由はわかりません。カスタムシリアル化は行いません。フレームワークに処理させます。
誰かがこれが起こっている理由と私がどのように行動を制御するのか説明できますか?
ここでは、要素と属性を含むxsdの部分です。 編集:問題の属性はバージョンです
<xs:schema xmlns:b="http://some.namespace.com/" xmlns="http://someothernamespace.com/" elementFormDefault="qualified" targetNamespace="http://someothernamespace.com/" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:include schemaLocation="JobPositionPosting.xsd" />
<xs:element name="Envelope">
<xs:complexType>
<xs:sequence>
<xs:element ref="Sender" />
<xs:element minOccurs="0" ref="TransactInfo" />
<xs:element maxOccurs="unbounded" ref="Packet" />
</xs:sequence>
<xs:attribute fixed="0.52" name="version" type="xs:string" use="required" />
</xs:complexType>
</xs:element>
そして、これが生成されたコードです。
/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "4.0.30319.1")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true, Namespace = "<removed>")]
[System.Xml.Serialization.XmlRootAttribute(Namespace = "http://somenamespace.com", IsNullable = false)]
public partial class Envelope
{
/// <remarks/>
public Sender Sender;
/// <remarks/>
public TransactInfo TransactInfo;
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute("Packet")]
public Packet[] Packet;
/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute("version")]
public string version;
public Envelope()
{
this.version = "0.52";
}
}
そして、これがRESTサービスから返されたxml、つまりシリアル化されたオブジェクトです。
<!-- (the rest o the xml is left out on purpose) -->
<Envelope>
<senderField i:nil="true"/>
<transactInfoField i:nil="true"/>
<versionField>0.52</versionField>
</Envelope>
ありがとう!