Change name of elements

Asked

Viewed 196 times

1

I would like to clarify some doubts since I do not have much experience with Web-Services and, currently, I have been tasked to review and implement some changes in an already deployed system. For the inexperience, I am facing basic difficulties to understand and modify certain parts of the code conferred to me.

The problem: I need to properly map the response elements for a given operation. The response object consists of the following elements:

<operacaoResponse xmlns="namespace">
    <sucesso xmlns="namespace"></sucesso>
    <mensagem xmlns="namespace"></mensagem>
    <documento xmlns="namespace">
                                 ...</documento>
</operacaoResponse>

where <documento> is a complex element.

The class that implements such an object is coded as follows:

    [System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
    [System.ServiceModel.MessageContractAttribute(WrapperName="operacaoResponse", WrapperNamespace="namespace", IsWrapped=true)]
    public partial class operacaoResponse {

    [System.ServiceModel.MessageBodyMemberAttribute(Namespace="namespace", Order=0)]
    [System.Xml.Serialization.XmlElementAttribute(Namespace="namespace")]
    public bool sucesso;

    [System.ServiceModel.MessageBodyMemberAttribute(Namespace="namespace", Order=1)]
    [System.Xml.Serialization.XmlElementAttribute(Namespace="namespace")]
    public string mensagem;

    [System.ServiceModel.MessageBodyMemberAttribute(Namespace="namespace", Order=2)]
    [System.Xml.Serialization.XmlElementAttribute(Namespace="namespace")]
    public Package.tipoDocumento documento;

The document object must be formatted as follows:

<documento>
    <a></a>
    <b></b>
    <c></c>
</documento>

And the class "typeDocument" is implemented as follows:

[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.0.30319.34234")]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="namespace")]
public partial class tipoDocumento {

    private tipoA aField;

    private tipoB[] bField;

    private tipoC[] cField;

    /// <remarks/>
    public tipoA aField {
        get {
            return this.aField;
        }
        set {
            this.aField = value;
        }
    }
...

My question is: how to make the afield Property can be mapped following the xml standard described above? I refer to element nomenclature. Even when I specify an Xmlelement to the Property and set a new Elementname the information is generated following the original nomenclature of the Property.

    [System.Xml.Serialization.XmlElementAttribute(ElementName="a", Order="0")
    public tipoA aField {
        get {
            return this.aField;
        }
        set {
            this.aField = value;
        }
    }
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.