Search code examples
xmlnode.jssoapwsdlsoap-client

Node-soap XML syntax


I'm trying to consume a SOAP WebService defined with this and this WSDLs with node-soap in node.js.

Now, regarding this part of the singlewsdl specification:

<xs:element minOccurs="0" name="AuthToken" nillable="true" type="xs:string"/>
<xs:element xmlns:q1="http://schemas.microsoft.com/2003/10/Serialization/Arrays" minOccurs="0" name="NIP" nillable="true" type="q1:ArrayOfstring"/>
...   
<xs:element minOccurs="0" name="DateFrom" nillable="true" type="xs:dateTime"/>

I have no problem querying the service with the AuthToken or DateFrom arguments:

var args = {
    AuthToken: 'yyyy',
    DateFrom: (ISOstringed date variable)
};

yet I have no clue how the syntax for "ArrayOf..." arguments should look like. I've tried:

NIP: 'xxxx'
NIP: {
    element: 'xxxx'
}
NIP: {
    string: 'xxxx'
}

yet only the first one produces a deserialization error, the former only produce timeouts (which is the same as for random arguments).

Any help would be appreciated.


Solution

  • SoapUI helped me to understand that this:

    <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tem="http://tempuri.org/" xmlns:arr="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
       <soapenv:Header/>
       <soapenv:Body>
          <tem:GetData>
             <tem:AuthToken>xxxx</tem:AuthToken>
             <tem:NIP>
                <arr:string>yyyy</arr:string>
                <arr:string>zzzz</arr:string>
             </tem:NIP>
          </tem:GetData>
       </soapenv:Body>
    </soapenv:Envelope>
    

    is the desired XML request format, so I went to make it as close as possible:

    var args = {
        attributes: {
            'xmlns:arr': 'http://schemas.microsoft.com/2003/10/Serialization/Arrays'
        },
        'tns:AuthToken': 'xxxx',
        'tns:NIP': {
            'arr:string': ['yyyy','zzzz']
        },
    };
    

    As a word of comment - node-soap defines the http://tempuri.org/ namespace as 'tns' by default, so I skipped the 'tem' definition that SoapUI suggested.