【发布时间】:2019-11-04 18:03:33
【问题描述】:
我正在尝试将此 xml 构建为输出,以发送到服务器:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tem="http://tempuri.org/" xmlns:agil="http://schemas.datacontract.org/2004/07/Agillitas.Servico.ContratosDeServico">
<soapenv:Header/>
<soapenv:Body>
<tem:Integrar>
<tem:request>
<agil:Cabecalho>
<agil:Metodo>44</agil:Metodo>
<agil:PublicKey>PUBLIC_KEY</agil:PublicKey>
<agil:Senha>PASSWORD</agil:Senha>
<agil:Usuario>USER</agil:Usuario>
</agil:Cabecalho>
<agil:Corpo>
<![CDATA[
<CartaoDisponivelTesouraria>
<Empresa>XXXX</Empresa>
<Produto>X</Produto>
<Moeda>XXX</Moeda>
</CartaoDisponivelTesouraria>
]]>
</agil:Corpo>
</tem:request>
</tem:Integrar>
</soapenv:Body>
</soapenv:Envelope>
我已经创建了一个类来做这件事......
const soap = require('soap')
module.exports = {
async run_method_44() {
// attempt 1
var args = {
$xml: "<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tem="http://tempuri.org/"xmlns:agil="http://schemas.datacontract.org/2004/07/Agillitas.Servico.ContratosDeServico"><soapenv:Header/><soapenv:Body><tem:Integrar><tem:request><agil:Cabecalho><agil:Metodo>44</agil:Metodo><agil:PublicKey>PUBLIC_KEY</agil:PublicKey><agil:Senha>PASSWORD</agil:Senha><agil:Usuario>USER</agil:Usuario></agil:Cabecalho><agil:Corpo><![CDATA[<CartaoDisponivelTesouraria><Empresa>XXXX</Empresa><Produto>X</Produto><Moeda>XXX</Moeda></CartaoDisponivelTesouraria>]]></agil:Corpo></tem:request></tem:Integrar></soapenv:Body></soapenv:Envelope>"
}
// attempt 2
var args2 = {
_xml: {'soapenv:Envelope': {
attributes: {
'xmlns:soapenv': 'http://schemas.xmlsoap.org/soap/envelope/',
'xmlns:tem': 'http://tempuri.org/',
'xmlns:agil': 'http://schemas.datacontract.org/2004/07/Agillitas.Servico.ContratosDeServico',
},
'soapenv:Body': {
'tem:Integrar': {
'tem:request': {
'agil:Cabecalho': {
'agil:Metodo': 44,
'agil:PublicKey': "PUBLIC_KEY",
'agil:Senha': "PASSWORD",
'agil:Usuario': "USER"
},
'agil:Corpo': '<![CDATA[<CartaoDisponivelTesouraria><Empresa>XXXX</Empresa><Produto>X</Produto><Moeda>XXX</Moeda></CartaoDisponivelTesouraria>]]>'
}
}
}
}}
}
// client
client.Integrar(args, function(err, result, rawResponse, soapHeader, rawRequest) {
console.log(result)
console.log(rawResponse)
console.log(soapHeader)
console.log(rawRequest)
console.log(err)
}, {postProcess: function(_xml) {
console.log(_xml)
return _xml.replace('IAdminService_Integrar_InputMessage', 'Integrar')
}})
}
}
发送到服务器的最终 XML 与我所期望的完全不同......
谁能帮我弄清楚如何防止在最终请求时创建一些奇怪的标签?
那么问题来了:
我输出的 XML 完全不同然后我期望... 我尝试了不同的解决方案,但似乎没有任何效果......有人遇到过类似的情况来提示如何解决这个问题吗?
【问题讨论】:
标签: node.js xml soap soap-client