gpt4 book ai didi

javascript - 无法解析响应 SOAP Node.js

转载 作者:搜寻专家 更新时间:2023-11-01 00:39:16 25 4
gpt4 key购买 nike

首先抱歉我的英语不好,其次我有一个关于在 Node.js 中使用 SOAP 的问题。我是 node.js 的初学者,我需要帮助。这是我的功能:

var soap = require('soap');

var url = 'http://SOMETHING?wsdl';

var args = {
accountId: 'xxxxx',
userName: 'xxxxx',
password: 'xxxxxx',
targetNSAlias: 'tns',
targetNamespace: 'http://api.ilient.com/'
};

soap.createClient(url, function(err, client) {
if(err) throw err;
client.login(args,function(err, result, raw, soapHeader){
if(err) throw err;
console.log(result);
});
});

当我运行时出现这个错误:

Error: Cannot parse response
at /root/node_modules/soap/lib/client.js:321:21
at Request._callback (/root/node_modules/soap/lib/http.js:117:5)
at Request.self.callback (/root/node_modules/request/request.js:186:22)
at Request.emit (events.js:98:17)
at Request.<anonymous> (/root/node_modules/request/request.js:1081:10)
at Request.emit (events.js:95:17)
at IncomingMessage.<anonymous> (/root/node_modules/request/request.js:1001:12)
at IncomingMessage.g (events.js:180:16)
at IncomingMessage.emit (events.js:117:20)
at _stream_readable.js:944:16

有人可以帮我解决吗?再次感谢并为我的英语感到抱歉。

最佳答案

我遇到了类似的问题。也许您尝试使用的 SOAP Web 服务具有 v1.2 规范,它可能期望内容类型为 application/soap+xml 而不是 text/xml。为了强制 node-soap 使用 SOAP 1.2 版本,您可以在 createClient() 参数中添加 forceSoap12Headers: true

附带说明,我必须将 ws-addressing header 添加到 soap header ,因为 由于 AddressFilter 不匹配,接收方无法处理带有“”的消息在 EndpointDispatcher 错误处。

我按如下方式编辑了您的代码:

var soap = require('soap');
var url = 'http://SOMETHING?wsdl';
var args = {
accountId: 'xxxxx',
userName: 'xxxxx',
password: 'xxxxxx',
targetNSAlias: 'tns',
targetNamespace: 'http://api.ilient.com/'
};

var soapOptions = {
forceSoap12Headers: true
};

var soapHeaders = {
'wsa:Action': 'http://tempuri.org/MyPortName/MyAction',
'wsa:To': 'http://SOMETHING.svc'
};

soap.createClient(url, soapOptions, function(err, client) {
if(err) throw err;
client.addSoapHeader(soapHeaders, '', 'wsa', 'http://www.w3.org/2005/08/addressing');
client.login(args, function(err, result, raw){
if(err) throw err;
console.log(result);
});
});

关于javascript - 无法解析响应 SOAP Node.js,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40803205/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com