2017-08-24 91 views
0

创建一个自定义的请求这是我需要发送到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> 

我有这样的代码:

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) 
    }); 

}); 

导致此:

<?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> 

我需要改变标签soapenv:Envelope的属性,但我不知道该怎么做。

我只是需要这些属性:

> xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" 
> xmlns:tem="http://tempuri.org/" 

任何帮助将不胜感激

回答

0

可能这不是最好的解决方案,但它为我工作。 在回调createCliete覆盖client.wsdl.xmlnsInEnvelope白衣,我想的xmlns属性,client.wsdl.xmlnsInEnvelope = 'xmlns:tem="http://tempuri.org/"';

的完整代码:

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) 
     }); 

    }); 

结果:

<?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>