繁体   English   中英

无法解析响应SOAP Node.js

[英]Cannot parse response SOAP Node.js

首先,对我的英语感到抱歉,其次,我对在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。 为了强制节点肥皂使用SOAP 1.2版本,您可以在createClient()参数之间添加forceSoap12Headers:true

在旁注中, 由于在EndpointDispatcher错误时AddressFilter不匹配,因此无法在接收方处理带有To''的消息 ,因此我不得不将ws-addressing头添加到soap头。

我对您的代码进行了如下编辑:

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

添加以下代码: client.setSecurity(new soap.BasicAuthSecurity('username', 'password')); 在创建客户端代码之后。 它为我工作:

var soap = require('soap');
var url = 'http://SOMETHING?wsdl';
soap.createClient(url, function(err, client) {
if(err) throw err;   
  client.setSecurity(new soap.BasicAuthSecurity('username', 'password'));
  client.login(args, function(err, result) {
  if(err) throw err;   
        console.log(result);
   });
});

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM