Accessing webservice with SOAP Headers and Node.js

1

I'm trying to access a webservice using Node.js (with module node-soap ) and that I first need to log in and then in the calls of other methods it is necessary to send the received Header in the login. I can log in and below the xml 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 can not send the received Header together. I'm using noad-soap's addSoapHeader method 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 a duplicate element. Notice that when inserting the Header 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 received Header to Login in the Request of the other methods?

    
asked by anonymous 20.07.2017 / 21:01

0 answers