[英]How to create a custom request using node-soap
This is the message I need to send to wsdl
: 这是我需要发送给
wsdl
的消息:
<?xml version="1.0" encoding="UTF-8" ?>
<soapenv:Envelope
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:tem="http://tempuri.org/">
<soapenv:Header/>
<soapenv:Body>
<tem:ConsultarCreditos>
<tem:usuario>DEMO010233001</tem:usuario>
<tem:password>Pruebas1a$</tem:password>
</tem:ConsultarCreditos>
</soapenv:Body>
</soapenv:Envelope>
I have this code: 我有以下代码:
const wsdlOptions = {
envelopeKey: "soapenv"
};
soap.createClient(URL, wsdlOptions, function(err, client) {
const args = {
_xml: '<tem:ConsultarCreditos><tem:usuario> DEMO010233001 </tem:usuario><tem:password>Pruebas1a$</tem:password></tem:ConsultarCreditos>',
}
client.ConsultarCreditos(args, function(err, result, raw, soapHeader) {
console.log('last request: ', client.lastRequest)
});
});
Which results this: 结果如下:
<?xml version="1.0" encoding="utf-8"?>
<soapenv:Envelope
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"
xmlns:tns="http://tempuri.org/"
xmlns:msc="http://schemas.microsoft.com/ws/2005/12/wsdl/contract">
<soapenv:Body>
<tem:ConsultarCreditos>
<tem:usuario>DEMO010233001</tem:usuario>
<tem:password>Pruebas1a$</tem:password>
</tem:ConsultarCreditos>
</soapenv:Body>
</soapenv:Envelope>
I need to change the attributes of the tag soapenv:Envelope
but I don't know how to do that. 我需要更改标签
soapenv:Envelope
的属性,但是我不知道该怎么做。
I just need these attributes: 我只需要这些属性:
> xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
> xmlns:tem="http://tempuri.org/"
Any help will be appreciated 任何帮助将不胜感激
May be this is no the best solution but it works for me. 可能这不是最好的解决方案,但对我有用。 In the callback createCliete override the property
client.wsdl.xmlnsInEnvelope
whit the xmlns that i want, client.wsdl.xmlnsInEnvelope = 'xmlns:tem="http://tempuri.org/"';
在回调createCliete中,覆盖属性
client.wsdl.xmlnsInEnvelope
和我想要的xmlns, client.wsdl.xmlnsInEnvelope = 'xmlns:tem="http://tempuri.org/"';
The complete code: 完整的代码:
soap.createClient(URL, wsdlOptions, function(err, client) {
client.wsdl.xmlnsInEnvelope = 'xmlns:tem="http://tempuri.org/"';
const args = {
_xml: '<tem:ConsultarCreditos><tem:usuario> DEMO010233001 </tem:usuario><tem:password>Pruebas1a$</tem:password></tem:ConsultarCreditos>',
}
client.ConsultarCreditos(args, function(err, result, raw, soapHeader) {
console.log('last request: ', client.lastRequest)
});
});
Result: 结果:
<?xml version="1.0" encoding="utf-8"?>
<soapenv:Envelope
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:tem="http://tempuri.org/">
<soapenv:Body>
<tem:ConsultarCreditos>
<tem:usuario>DEMO010233001</tem:usuario>
<tem:password>Pruebas1a$</tem:password>
</tem:ConsultarCreditos>
</soapenv:Body>
</soapenv:Envelope>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.