I持ってそのスキーマ内で次の型が含まSOAPサービスのために作成されたWCFクライアント:移入XmlAnyAttribute
<xs:element name="foo" nillable="true">
<xs:complexType>
<xs:sequence>
<xs:element name="bar" type="xs:string"/>
</xs:sequence>
<xs:anyAttribute namespace="##other"/>
</xs:complexType>
</xs:element>
をと.NETは、次のクラスを生成:
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.6.1098.0")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true, Namespace="http://example.com/ws/entity")]
public partial class foo : object {
private string barField;
private System.Xml.XmlAttribute[] anyAttrField;
[System.Xml.Serialization.XmlElementAttribute(Order=0)]
public string bar {
get { return this.barField; }
set { this.barField = value; }
}
[System.Xml.Serialization.XmlAnyAttributeAttribute()]
public System.Xml.XmlAttribute[] AnyAttr {
get { return this.anyAttrField; }
set { this.anyAttrField = value; }
}
}
を何このクラスのAnyAttrプロパティを設定するための推奨される方法ですか? XmlAttribute
を作成する唯一の方法は、既存のXmlDocument
からのものです。この場合は、オブジェクトが途中で直列化されるまで作成されません。
私はIClientMessageInspector
でBeforeSendRequest
の要素に属性を追加しようとして始めたが、私は生のXmlDocument
を修正するために見つけることができる唯一の方法は、元のメッセージを交換、その後、それを変換し、Message
のコピーを作成することでした、これは属性を追加するだけの多くの作業のようでした。
結局、私がどのように見えるXML作成しようとしています:私はFoo
が定義されているサービスを所有して行う、と私はFoo
自体を変更することはできませんが、私はカスタム要素を追加することができる午前
...
<foo xmlns:ns2="http://example.com/ws/ext" ns2:other="some other value">
<bar>some value</bar>
</foo>
...