[SOLVED] Getting an Array from a SOAP XML response in NodeJS

Issue

This Content is from Stack Overflow. Question asked by BREAKWAVE

I’m working on a SOAP client in NodeJS. I’ve managed to consume using SOAPUi,the thing is that the response for the request I’m getting has an Array inside the body.

The XML request looks like this:

<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:xe="http://www.w3.org/2001/04/xmlenc#">
<soap:Header>
  <xe:AuthenticationHeader>
     <!--Optional:-->
     <xe:UserName>user</xe:UserName>
     <!--Optional:-->
     <xe:Password>password</xe:Password>
  </xe:AuthenticationHeader>
</soap:Header>
<soap:Body>
  <xe:GetRegistration>
     <!--Optional:-->
     <xe:id>123456</xe:id>
  </xe:GetRegistration>
</soap:Body>
</soap:Envelope>

And the response XML looks like this:

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<GetRegistrationResponse xmlns="http://www.w3.org/2001/04/xmlenc#"> 
<GetRegistrationResult>
<ErrorInQuery>false</ErrorInQuery>
<ErrorInfo>Success!</ErrorInfo>
<ArrayRegistration />
</GetRegistrationResult>
</GetRegistrationResponse>
</soap:Body>
</soap:Envelope>

What I’m trying to get from the response is that ArrayRegistration which will be processed by a decrypting process to give me the plain text results.

I managed to do it on C# but since the proyect needs to be done in NodeJS I have been struggling with it.

This is the code that worked for me in C#

  public partial class RRegistration : object, System.ComponentModel.INotifyPropertyChanged {
    
    private bool errorQuery;
    
    private string errorInformation;
    
    private Registration[] arrayRegistrationField;
    
    /// <remarks/>
    [System.Xml.Serialization.XmlElementAttribute(Order=0)]
    public bool ErrorInQuery {
        get {
            return this.errorQuery;
        }
        set {
            this.errorQuery = value;
            this.RaisePropertyChanged("ErrorQuery");
        }
    }
    
    /// <remarks/>
    [System.Xml.Serialization.XmlElementAttribute(Order=1)]
    public string ErrorInformation {
        get {
            return this.errorInformation;
        }
        set {
            this.errorInformation = value;
            this.RaisePropertyChanged("ErrorInformation");
        }
    }
    
    /// <remarks/>
    [System.Xml.Serialization.XmlArrayAttribute(Order=2)]
    public Registration[] ArrayRegistration {
        get {
            return this.arrayRegistration;
        }
        set {
            this.arrayRegistration = value;
            this.RaisePropertyChanged("ArrayRegistration");
        }
    }
    
    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));
        }
    }
}

Honestly any help would be greatly appreciated, in NodeJS I’ve used Node-Soap and easy-soap-request but I’m not sure how to get the Array that I need to send to the decrypting method.



Solution

At the end the xml that I was sending was missing the xe: notation in each of the custom tags.


This Question was asked in StackOverflow by BREAKWAVE and Answered by BREAKWAVE It is licensed under the terms of CC BY-SA 2.5. - CC BY-SA 3.0. - CC BY-SA 4.0.

people found this article helpful. What about you?