2017-05-01 10 views
1

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からのものです。この場合は、オブジェクトが途中で直列化されるまで作成されません。

私はIClientMessageInspectorBeforeSendRequestの要素に属性を追加しようとして始めたが、私は生のXmlDocumentを修正するために見つけることができる唯一の方法は、元のメッセージを交換、その後、それを変換し、Messageのコピーを作成することでした、これは属性を追加するだけの多くの作業のようでした。

結局、私がどのように見えるXML作成しようとしています:私はFooが定義されているサービスを所有して行う、と私はFoo自体を変更することはできませんが、私はカスタム要素を追加することができる午前

... 
    <foo xmlns:ns2="http://example.com/ws/ext" ns2:other="some other value"> 
    <bar>some value</bar> 
    </foo> 
... 

答えて

0

をスキーマそのため、スキーマ内の既存のxs:anyAttributeを試す代わりに、私は自分のデータに新しい要素を追加しました。