我正在通过使用node.js(Express)使用SOAP,这是我第一次在节点上使用SOAP。我需要捕获节点根父节点(<soap:Envelope...>
)并修改/添加特定的名称空间声明:
我可以添加到主体部分,但不能添加到父根节点(<soap:Envelope...>
)中,我还尝试使用了overrideRootElement,但结果仍然不是我所需要的。
服务
const service = {
Gateway: {
GatewaySoap: {
RequestTest: function (args, cb, headers, req) {
return args; // FINE
},
}
}
}
app.listen(port, function () {
server = soap.listen(app, {
path: '/wp',
services: service,
xml: xml,
overrideRootElement: {
namespace: 'xmlns:tns',
envelopeKey:'soapenv',
xmlnsAttributes: [
{
name: 'xmlns:xsi',
value: "http://www.w3.org/2001/XMLSchema-instance"
},
{
name: 'xmlns:xsd',
value: 'http://www.w3.org/2001/XMLSchema'
}
]
}
});
server.on('request', function(xml, eid) {
console.log('::',xml);
})
});
结果(使用SoapUI)
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:tns="http://tempuri.org/"
xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/">
<soap:Body>
<xmlns:tns:TestResponse xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
</xmlns:tns:TestResponse>
</soap:Body>
</soap:Envelope>
预期结果
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:tns="http://tempuri.org/"
xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<xmlns:tns:TestResponse>
</xmlns:tns:TestResponse>
</soap:Body>
</soap:Envelope>
PD: