3

I'm having trouble properly formatting one particular soap parameter using the node-soap module for node.js as a client, to a 3rd-party SOAP service.

The client.describe() for this method says this particular input should be in the shape of:

params: { 'param[]': {} }

I have tried a bunch of different JSON notations to try to fit my data to that shape. Examples of formats that do NOT work:

"params": { "param": [ {"myParameterName": "myParameterValue"} ] }
"params": [ "param": { "name": "myParameterName", "_": "myParameterValue"} ]
"params": { "param" : [ {"name": "myParameterName", "_": "myParameterValue"} ] }
"params": { "param[]": {"myParameterName": "myParameterValue" } }
"params": { "param[myParameterName]": {"_": "myParameterValue" } }

I must be overlooking something, and I suspect I'm going to feel like Captain Obvious when some nice person points out what I'm doing wrong.

Here is what DOES work, using other soap clients, and how they handle the "named parameter with a value"

soapUI for this method successfully accepts this particular input via XML in the shape of:

<ns:params>
    <ns:param name="myParameterName">myParameterValue</ns:param>
</ns:params>

Also, using PHP, I can successfully make the call by creating a stdClass of arrays like so:

$parms = new stdClass;
$parms->param = array(
    array(
        "name"=>"myParameterName","_"=>"myParameterValue"
    )
);

and then eventually passing

'params' => $parms 

to the PHP soap client

Many thanks!

pdapel
  • 146
  • 1
  • 7

1 Answers1

8

To get a better look at what XML was being generated by node-soap, I added a console.log(message) statement to the node_modules/soap/lib/client.js after the object-to-XML encoding. I then began experimenting with various JSON structures to figure out empirically how they were mapping to XML structures.

I found a JSON structure for node-soap to generate the XML in my 3rd-party's required named-parameter-with-value format. I was completely unaware of the "$value" special keyword. Looks like this may have been added in the 0.4.6 release from mid-June 2014. See the change history

"params": [
  { 
    "param": {
       "attributes": {
          "name": "myParameterName"
       },
       $value: "myParameterValue"
    } 
  }
]

(note the outer array, which gives me the luxury of specifying multiple "param" entries, which is sometimes needed by this particular 3rd-party API)

generates this XML:

<tns:params>
  <tns:param name="myParameterName">myParameterValue</tns:param>
</tns:params>

which perfectly matches the structure in soapUI (which I already knew worked) of:

<ns:params>
    <ns:param name="myParameterName">myParameterValue</ns:param>
</ns:params>
pdapel
  • 146
  • 1
  • 7