sagarpatil232
sagarpatil232

Reputation: 33

node js soap request error: Unexpected root element of WSDL or include

I am trying to integrate a soap api in node.js by using soap module. When I hit the api, the error i am getting is 'Unexpected root element of WSDL or include'.These are details of the 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>

And the node js code that i have written is as follows:

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

I think this error comes from the soap module. So is there something which I am missing in the request or what headers should be set in order to make the nodejs code work?

Upvotes: 0

Views: 2706

Answers (1)

Terry Lennox
Terry Lennox

Reputation: 30675

Try changing the url to http://www.dneonline.com/calculator.asmx?WSDL

e.g.

var url = 'http://www.dneonline.com/calculator.asmx?WSDL';

I've created a simple call to the add method below:

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

I get the result below:

Creating client..
Client created..
result  { AddResult: 3 }

Upvotes: 2

Related Questions