Dmitriy
Dmitriy

Reputation: 207

SOAP deserialization: null fields of base class


I have some classes generated from WSDL (by VS add service reference):

getClientDataResponseType:

[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.7.2558.0")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://api.company.ru/sid/paymenttemplates")]
public partial class getClientDataResponseType : baseResponse {

    private object[] itemsField;

    /// <remarks/>
    [System.Xml.Serialization.XmlElementAttribute("clientData", typeof(clientDataWithId), Order=0)]
    [System.Xml.Serialization.XmlElementAttribute("clientNotFoundExceptionResponse", typeof(clientNotFoundExceptionResponseType), Order=0)]
    [System.Xml.Serialization.XmlElementAttribute("genericExceptionResponse", typeof(genericExceptionResponseType), Order=0)]
    [System.Xml.Serialization.XmlElementAttribute("templateList", typeof(templateList), Order=0)]
    public object[] Items {
        get {
            return this.itemsField;
        }
        set {
            this.itemsField = value;
            this.RaisePropertyChanged("Items");
        }
    }
}

templateList:

[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.7.2558.0")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://api.company.ru/sid/paymenttemplates")]
public partial class templateList : object, System.ComponentModel.INotifyPropertyChanged {

    private templateListElement[] templateField;

    /// <remarks/>
    [System.Xml.Serialization.XmlElementAttribute("template", Order=0)]
    public templateListElement[] template {
        get {
            return this.templateField;
        }
        set {
            this.templateField = value;
            this.RaisePropertyChanged("template");
        }
    }

    public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;

    protected void RaisePropertyChanged(string propertyName) {
        System.ComponentModel.PropertyChangedEventHandler propertyChanged = this.PropertyChanged;
        if ((propertyChanged != null)) {
            propertyChanged(this, new System.ComponentModel.PropertyChangedEventArgs(propertyName));
        }
    }
}

templateListElement:

[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.7.2558.0")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://api.company.ru/sid/paymenttemplates")]
public partial class templateListElement : templateType {

    private string templateIdField;

    /// <remarks/>
    [System.Xml.Serialization.XmlElementAttribute(Order=0)]
    public string templateId {
        get {
            return this.templateIdField;
        }
        set {
            this.templateIdField = value;
            this.RaisePropertyChanged("templateId");
        }
    }
}

and finally templateType:

[System.Xml.Serialization.XmlIncludeAttribute(typeof(templateListElement))]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.7.2558.0")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://api.company.ru/sid/paymenttemplates")]
public partial class templateType : object, System.ComponentModel.INotifyPropertyChanged {

    private string descriptionField;

    private string accountIdField;

    private string processingSystemField;

    private string templateType1Field;

    private templateAttributeList attributesField;

    /// <remarks/>
    [System.Xml.Serialization.XmlElementAttribute(Order=0)]
    public string description {
        get {
            return this.descriptionField;
        }
        set {
            this.descriptionField = value;
            this.RaisePropertyChanged("description");
        }
    }

    /// <remarks/>
    [System.Xml.Serialization.XmlElementAttribute(Order=1)]
    public string accountId {
        get {
            return this.accountIdField;
        }
        set {
            this.accountIdField = value;
            this.RaisePropertyChanged("accountId");
        }
    }

    /// <remarks/>
    [System.Xml.Serialization.XmlElementAttribute(Order=2)]
    public string processingSystem {
        get {
            return this.processingSystemField;
        }
        set {
            this.processingSystemField = value;
            this.RaisePropertyChanged("processingSystem");
        }
    }

    /// <remarks/>
    [System.Xml.Serialization.XmlElementAttribute("templateType", Order=3)]
    public string templateType1 {
        get {
            return this.templateType1Field;
        }
        set {
            this.templateType1Field = value;
            this.RaisePropertyChanged("templateType1");
        }
    }

    /// <remarks/>
    [System.Xml.Serialization.XmlElementAttribute(Order=4)]
    public templateAttributeList attributes {
        get {
            return this.attributesField;
        }
        set {
            this.attributesField = value;
            this.RaisePropertyChanged("attributes");
        }
    }

    public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;

    protected void RaisePropertyChanged(string propertyName) {
        System.ComponentModel.PropertyChangedEventHandler propertyChanged = this.PropertyChanged;
        if ((propertyChanged != null)) {
            propertyChanged(this, new System.ComponentModel.PropertyChangedEventArgs(propertyName));
        }
    }
}

and when i got responce from web service, props defined in base templateType class was filling nulls values, and only templateIdField defined in derived templateListElement class was parsed correct

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:pa="http://api.company.ru/sid/paymenttemplates">
  <SOAP-ENV:Header />
  <SOAP-ENV:Body>
    <pa:getClientDataResponse>
      <pa:return>1</pa:return>
      <pa:returnCode>0</pa:returnCode>
      <pa:clientData>
        <pa:surname>Abernathy</pa:surname>
        <pa:name>Dolores</pa:name>
        <pa:patronymic>not_present</pa:patronymic>
        <pa:birthDate>1979-07-05</pa:birthDate>
        <pa:document>
          <pa:docType>21</pa:docType>
          <pa:docNumber>577507</pa:docNumber>
          <pa:docDate>2002-11-12</pa:docDate>
        </pa:document>
        <pa:clientId>6ef27ac9-1a42-430e-bd2f-9cfb8a824b7e</pa:clientId>
      </pa:clientData>
      <pa:templateList>
        <template xmlns="http://api.company.ru/sid/paymenttemplates">
          <templateId>26236b96-69ed-49be-9be7-74e0342e50bf</templateId>
          <templateType>HashPAN</templateType>
          <description>some_description</description>
          <accountId>234234234</accountId>
          <processingSystem>TCS</processingSystem>
          <attributes>
          </attributes>
        </template>
        <template xmlns="http://api.company.ru/sid/paymenttemplates">
          <templateId>fc124296-4ff4-4842-a78c-2ff92b100c88</templateId>
          <templateType>Other</templateType>
          <description>some_description</description>
          <accountId>79048931512</accountId>
          <processingSystem>TCH</processingSystem>
          <attributes>
            <attribute>
              <name>owner_family</name>
              <value>Dolores</value>
            </attribute>
            <attribute>
              <name>owner_name</name>
              <value>Abernathy</value>
            </attribute>
            <attribute>
              <name>owner_patronymic</name>
              <value>not_present</value>
            </attribute>
          </attributes>
        </template>
      </pa:templateList>
    </pa:getClientDataResponse>
  </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

test code

var result2 = client.getClientData(new getClientDataRequestType {token = tok, codeDoc = controlNumber});

templateListElement template = null;
clientDataWithId data = null;
foreach (var item in result2.Items)
    if (item is templateList)
    {
        var list = (templateList) item;
        foreach (var t in list.template)
            Helper.Log(t.ObjToString());
    }
    else if (item is clientDataWithId)
    {
        data = (clientDataWithId) item;
        Helper.Log(data.ObjToString());
    }
    else
    {
        throw new ApplicationException("Unknown item type!");
    }

as you can see null values was logged here for all props defined in base class (description, accountId, processingSystem etc..)

[2018.07.10 12.37.20] TemplateServiceReference.templateListElement
templateId: 26236b96-69ed-49be-9be7-74e0342e50bf
description: (null)
accountId: (null)
processingSystem: (null)
templateType1: (null)
attributes: (null)

[2018.07.10 12.37.20] TemplateServiceReference.templateListElement
templateId: fc124296-4ff4-4842-a78c-2ff92b100c88
description: (null)
accountId: (null)
processingSystem: (null)
templateType1: (null)
attributes: (null)

Can anybody help me solve this trouble?

Upvotes: 1

Views: 425

Answers (1)

Dmitriy
Dmitriy

Reputation: 207

The problem was in elements ORDER in responce. It dosnt match the WSDL schema. I just delete order=0,1,2 etc.. from attrs props and deserialization now work correct!

Upvotes: 1

Related Questions