Reputation: 305
How to configure node-soap client set namespace for array not only for objects?
My params for 'sendPatient' method:
params = {
patientCard: {
patient: {
firstName: 'test',
lastName: 'test'
},
identifiers:
{
code: "123456789",
codeType: 1
}
}
};
client.sendPatient(params, ...)
node-soap produce:
<soap:Envelope
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:tns="http://xxx/patient/api/"
xmlns:bi="http://xxx/base/info/build/">
<soap:Header></soap:Header>
<soap:Body>
<tns:sendPatient
xmlns:tns="http://xxx/patient/api/"
xmlns="http://xxx/patient/api/">
<tns:patientCard>
<ns1:patient
xmlns:ns1="http://xxx/patient/">
<ns1:firstName>test</ns1:firstName>
<ns1:lastName>test</ns1:lastName>
</ns1:patient>
<ns1:identifiers
xmlns:ns1="http://xxx/patient/">
<ns1:code>123456789</ns1:code>
<ns1:codeType>1</ns1:codeType>
</ns1:identifiers>
</tns:patientCard>
</tns:sendPatient>
</soap:Body>
</soap:Envelope>
and it's works, but I need to send array of identifiers, not only one, so when I put array
params = {
patientCard: {
patient: {
firstName: 'test',
lastName: 'test'
},
identifiers: [
{
code: "123456789",
codeType: 1
}, {
code: "987654321",
codeType: 2
}
]
}
};
node-soap produce:
<soap:Envelope
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:tns="http://xxx/patient/api/"
xmlns:bi="http://xxx/base/info/build/">
<soap:Header></soap:Header>
<soap:Body>
<tns:sendPatient
xmlns:tns="http://xxx/patient/api/"
xmlns="http://xxx/patient/api/">
<tns:patientCard>
<ns1:patient
xmlns:ns1="http://xxx/patient/">
<ns1:firstName>test</ns1:firstName>
<ns1:lastName>test</ns1:lastName>
</ns1:patient>
<ns1:identifiers>
<ns1:code>00100180035</ns1:code>
<ns1:codeType>1</ns1:codeType>
</ns1:identifiers>
<ns1:identifiers>
<ns1:code>00100180035</ns1:code>
<ns1:codeType>1</ns1:codeType>
</ns1:identifiers>
</tns:patientCard>
</tns:sendPatient>
</soap:Body>
</soap:Envelope>
and I get error from server for <ns1:identifiers>
part
`[com.ctc.wstx.exc.WstxParsingException: Undeclared namespace prefix "ns1" at [row,col {unknown-source}]: [17,25]]`
What am I doing wrong? Can I somehow add xmlns:ns1="http://xxx/patient/"
to <soap:Envelope>
tag or configure node-soap to add it for arrays too (not for only simple objects)?
P.S. Sorry for my English
Upvotes: 6
Views: 8321
Reputation: 1482
I was unable to call _xmlnsMap
because of the error "Property '_xmlnsMap' is private and only accessible within class 'WSDL'.ts(2341)".
Instead I did this:
if (!soapClient['wsdl'].xmlnsInEnvelope.includes('xmlns:ns1=')) {
soapClient['wsdl'].xmlnsInEnvelope += 'xmlns:ns1="http://xxx/patient/"';
}
The if
condition is unnecessary if you only execute it once against the soapClient
and you know your WSDL doesn't already have the ns1
namespace.
Upvotes: 1
Reputation: 119
In typescript you can access to private wsdl as Swarthy comments, but appending the namespace directly:
client['wsdl'].xmlnsInEnvelope += 'xmlns:ns1="http://xxx/patient/"';
client['wsdl']._xmlnsMap();
Upvotes: 1
Reputation: 305
Published temporary solution on Github
after createClient patch wsdl definitions
soap.createClient(wsdl, options, function(err, client) {
client.wsdl.definitions.xmlns.ns1 = 'http://xxx/patient/'
client.wsdl.xmlnsInEnvelope = client.wsdl._xmlnsMap()
//works now
client.sendPatient(...)
});
Upvotes: 19