XmlTypeAttribute does not change name of type

这一生的挚爱 提交于 2019-12-23 21:22:40

问题


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

The SOAP type comes across the wire as "address". I'm not sure why XmlTypeAttribute is not affecting it, or why it is coming across lower case.

Thoughts on what I might be doing wrong, or a better way to accomplish 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; }
    }
}

回答1:


[XmlType] changes the name of the complexType in the schema. It does not change element names in the XML.

Use [XmlElement(ElementName="MyAddress", Namespace="your namespace")] instead.



来源:https://stackoverflow.com/questions/1579982/xmltypeattribute-does-not-change-name-of-type

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!