node-soap 客户端 (Node.js) 中数组字段的命名空间 [英] Namespace for array field in node-soap client (Node.js)
问题描述
如何为数组配置 node-soap 客户端集命名空间,而不仅仅是为对象?
How to configure node-soap client set namespace for array not only for objects?
'sendPatient' 方法的参数:
My params for 'sendPatient' method:
params = {
patientCard: {
patient: {
firstName: 'test',
lastName: 'test'
},
identifiers:
{
code: "123456789",
codeType: 1
}
}
};
client.sendPatient(params, ...)
node-soap 生产:
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 生产:
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>
并且我从服务器收到 <ns1:identifiers>
部分的错误
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]]`
我做错了什么?我可以以某种方式将 xmlns:ns1="http://xxx/patient/"
添加到 <soap:Envelope>
标记或配置 node-soap 以将其添加到数组也是(不仅仅是简单的对象)?附言对不起我的英语
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
推荐答案
Published temporary solution on Github
createClient 补丁 wsdl 定义之后
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(...)
});
这篇关于node-soap 客户端 (Node.js) 中数组字段的命名空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!