XmlTypeAttribute does not change type name

I am working on a project that calls a web service using WSE3. Types originally created using VS2005 have changed over time. Now I need to change the type name in the SOAP message. I understand that this should be done using XmlTypeAttribute, but this does not affect the type name. As an experiment, I used XmlElementAttribute in the property of this class, and this changed the name of the element generated for this property. The generated object has been extended using partial classes.

The SOAP type meets the wire as an "address". I am not sure why XmlTypeAttribute does not affect it or why it is found in lower case.

Thoughts on what I can do wrong, or the best way to achieve the goal?

References.cs:

[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "2.0.50727.1434")]
[System.SerializableAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(TypeName = "MyAddress", Namespace = "http://sample.com/transaction")]
//                                                     ^-- Soap typenamed "address", not "MyAddress"
public partial class Address
{        
    private string address1Field;

    private string address2Field;

    private string[] jurisdictionsField;

    private System.DateTime resolvedDateField;

    private bool resolvedDateFieldSpecified;

    /// <remarks/>
    [System.Xml.Serialization.XmlElementAttribute("MyAddress1", Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
    //                                             ^--- SOAP element named "MyAddress1" as expected
    public virtual string Address1
    {
        get {
            return this.address1Field;
        }
        set {
            this.address1Field = value;
        }
    }

    /// <remarks/>
    [System.Xml.Serialization.XmlElementAttribute("address2", Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
    public virtual string Address2
    {
        get {
            return this.address2Field;
        }
        set {
            this.address2Field = value;
        }
    }        
}

Address.cs:

public partial class Address
{
    private int id;

    public virtual int Id
    {
        get { return id; }
        set { id = value; }
    }
}
+3
1

[XmlType] complexType . XML.

[XmlElement(Name="MyAddress", Namespace="your namespace")] .

+3

Source: https://habr.com/ru/post/1720314/


All Articles