[英]Cannot parse response SOAP Node.js
firstly sorry for my english, secondly I have a question about use of SOAP in Node.js. 首先,对我的英语感到抱歉,其次,我对在Node.js中使用SOAP有疑问。 I am a beginner with node.js and I need help.
我是node.js的初学者,需要帮助。 This is my function:
这是我的功能:
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);
});
});
when I run I get this error: 当我运行时,出现此错误:
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
someone can help me solve it? 有人可以帮我解决吗? Thanks and sorry for my english again.
再次感谢和抱歉我的英语。
I faced a similar problem. 我遇到了类似的问题。 Maybe the SOAP web service that you are trying to consume has v1.2 specification and it might expect the content type as application/soap+xml instead of text/xml.
也许您要使用的SOAP Web服务具有v1.2规范,并且可能期望内容类型为application / soap + xml而不是text / xml。 In order to force node-soap to use SOAP 1.2 version you could add forceSoap12Headers: true among createClient() parameters.
为了强制节点肥皂使用SOAP 1.2版本,您可以在createClient()参数之间添加forceSoap12Headers:true 。
On a side note, I had to add the ws-addressing headers to soap header because of The message with To ' ' cannot be processed at the receiver, due to an AddressFilter mismatch at the EndpointDispatcher error. 在旁注中, 由于在EndpointDispatcher错误时AddressFilter不匹配,因此无法在接收方处理带有To''的消息 ,因此我不得不将ws-addressing头添加到soap头。
I edited your code as follows: 我对您的代码进行了如下编辑:
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);
});
});
Add this code: client.setSecurity(new soap.BasicAuthSecurity('username', 'password'));
添加以下代码:
client.setSecurity(new soap.BasicAuthSecurity('username', 'password'));
after your create client code. 在创建客户端代码之后。 It worked for me:
它为我工作:
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.