我正在尝试使用soap模块在node.js中集成soap api。当我点击api时,我得到的错误是'WSDL的意外根元素或包含'。这些是soap api的详细信息:
POST /calculator.asmx HTTP/1.1
Host: www.dneonline.com
Content-Type: application/soap+xml; charset=utf-8
Content-Length: length
<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
<soap12:Body>
<Add xmlns="http://tempuri.org/">
<intA>int</intA>
<intB>int</intB>
</Add>
</soap12:Body>
</soap12:Envelope>
我编写的节点js代码如下:
var soap = require('soap');
var url = 'http://www.dneonline.com/calculator.asmx';
var add = function(req, res){
var args = {intA: 1,intB: 2};
var soapHeader = ''//xml string for header
soap.createClient(url, function(err, client) {
if(err){
res.status(400).send(err)
} else {
client.Add(args, function(err, result) {
console.log('result ',result);
res.send(result)
});
}
});
}
exports.add = add
我认为这个错误来自soap模块。那么我在请求中是否缺少某些东西或者为了使nodejs代码有效而应该设置哪些头文件?
答案 0 :(得分:1)
尝试将网址更改为http://www.dneonline.com/calculator.asmx?WSDL
e.g。
var url = 'http://www.dneonline.com/calculator.asmx?WSDL';
我已经创建了一个对下面的add方法的简单调用:
var soap = require('soap');
var url = 'http://www.dneonline.com/calculator.asmx?WSDL';
var args = {intA: 1,intB: 2};
console.log('Creating client..');
soap.createClient(url, function(err, client) {
if(err){
console.log('Error creating client: ', err);
} else {
console.log('Client created..');
client.Add(args, function(err, result) {
console.log('result ',result);
});
}
});
我得到以下结果:
Creating client..
Client created..
result { AddResult: 3 }