node-soap send array of strings

31 Views Asked by At

I'm trying to communicate with an .NET soap server in Node.js using node-soap (https://www.npmjs.com/package/soap)

When I test this with SoapUI the communication works as excepted. One of the data elements is an array of strings:

 <tre:Colors>
     <!--Zero or more repetitions:-->
     <arr:string>#333333</arr:string>
     <arr:string>#FF8800</arr:string>
     <arr:string>#FF8800</arr:string>
     <arr:string>#FF8800</arr:string>
     <arr:string>#FF8800</arr:string>
     <arr:string>#FF8800</arr:string>
 </tre:Colors>

I want to send this data with Node.js as well but I can't get it working.

Colors: ['#333333', '#FF8800', '#FF8800', '#FF8800', '#FF8800', '#FF8800']

Gives me an error from the backend because this xml is generated:

<q1:Colors xmlns:q1="http://schemas.datacontract.org/2004/07/[namespace]">#333333#FF8800#FF8800#FF8800#FF8800#FF8800</q1:Colors>

Since I only need to send a array of strings, I cannot make objects. How should I build this data to generate a correct request?

Edit: I tried it too with this request data:

Colors: [{$value: '#333333'}, {$value: '#FF8800'}, {$value: '#FF8800'}, {$value: '#FF8800'}, {$value: '#FF8800'}, {$value: '#FF8800'}]

Which generated this request:

<q1:Colors xmlns:q1="http://schemas.datacontract.org/2004/07/[namespace]">#333333</q1:Colors>
<q1:Colors xmlns:q1="http://schemas.datacontract.org/2004/07/[namespace]">#FF8800</q1:Colors>
<q1:Colors xmlns:q1="http://schemas.datacontract.org/2004/07/[namespace]">#FF8800</q1:Colors>
<q1:Colors xmlns:q1="http://schemas.datacontract.org/2004/07/[namespace]">#FF8800</q1:Colors>
<q1:Colors xmlns:q1="http://schemas.datacontract.org/2004/07/[namespace]">#FF8800</q1:Colors>
<q1:Colors xmlns:q1="http://schemas.datacontract.org/2004/07/[namespace]">#FF8800</q1:Colors>

When I explicitly set {namespaceArrayElements: false} as option in the createClient() function, I get the same result as above (everything in one string).

0

There are 0 best solutions below