1
I am trying to access a webservice using Node.js (with module Node-Soap) and that first I need to login and then in the calls of other methods it is necessary to send the received Header on login. I can login and follow the xml below with the Header and token received:
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Header>
<sessaoIdHeader xmlns="http://www.cvm.gov.br/webservices/">
<Guid>8710-f7ad-4e20-ac28-0a5a9587bc2b</Guid>
<IdSessao>270440</IdSessao>
</sessaoIdHeader>
</soap:Header>
<soap:Body><LoginResponse xmlns="http://www.cvm.gov.br/webservices/"/>
</soap:Body>
</soap:Envelope>
When I try to call another webservice method I am not able to send the received Header together. I’m using the addSoapHeader method from noad-Soap and the code looks like this:
soap.createClient(url, function(err, client) {
client.Login(args, function(err, result, headers) {
let data = {
tpDoc: 9,
entregDoc: '2017-03-31'
};
client.addSoapHeader(headers);
client.retornaListaComptcDocs(data, function(err, result) {
console.log(client.lastRequest);
console.log(result);
});
});
});
The lastRequest property shows that XML has duplicate element. Note that when you insert the Header the XML looks like this:
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/"
xmlns:tns="http://www.cvm.gov.br/webservices/">
<soap:Header>
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Header>
<sessaoIdHeader xmlns="http://www.cvm.gov.br/webservices/">
<Guid>8710-f7ad-4e20-ac28-0a5a9587bc2b</Guid>
<IdSessao>270440</IdSessao>
</sessaoIdHeader>
</soap:Header>
<soap:Body><LoginResponse xmlns="http://www.cvm.gov.br/webservices/"/>
</soap:Body>
</soap:Envelope>
</soap:Header>
<soap:Body>
<solicAutorizDownloadArqEntregaPorData
xmlns="http://www.cvm.gov.br/webservices/">
<iCdTpDoc>305</iCdTpDoc>
<strDtEntregaDoc>2017-07-17</strDtEntregaDoc>
</solicAutorizDownloadArqEntregaPorData>
</soap:Body>
</soap:Envelope>
How can I add the Header received in Login to the Request of the other methods?