SOAP Request

Post Reply
Sunnyland
Member
Posts: 56
Joined: Mon Aug 19, 2013 1:34 am

SOAP Request

Post by Sunnyland »

Have spent the last 6 hours trying to make a SOAP request from switch and NODEJS

I have tried to use node soap but I could get it working correctly, so then I have tried to use http
it is a simple request

var args = "<?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>" +
"<RunEvent xmlns='url'>" +
"<JobRef xmlns=''>" + jobRef + "</JobRef>" +
"<System xmlns=''>" + system + "</System>" +
"<EventType xmlns=''>" + eventType + "</EventType>" +
"<EventText xmlns=''>" + eventText + "</EventText>" +
"<FileRefs xmlns=''>" + fileRefs + "</FileRefs>" +
"</RunEvent>" +
"</soap12:Body>" +
"</soap12:Envelope>"

const sampleHeaders = {
'Content-Type': 'text/xml; charset=utf-8',
'Content-Length': args.length.toString(),
'Host': url,
'Connection': 'keep-alive'
};

var postoptions = {
hostname: url,
port:80,
method: 'POST',
path: '/WebService/ProductionIntegration.asmx',
headers: sampleHeaders
};

var req = http.request(postoptions, function(res){
console.log('STATUS: ' + res.statusCode);
console.log('HEADERS: ' + JSON.stringify(res.headers));
res.setEncoding('utf-8');
res.on('data', function(chunk){
console.log('BODY: ' + chunk);
});
});

req.on('error', function(e) {
console.log('problem with request: ' + e.message);
});

req.write(args);
req.end();

Should be pretty straight forward. I have done the same SOAP request in POSTMAN and it works fine. Any ideas what I am missing?
freddyp
Advanced member
Posts: 1008
Joined: Thu Feb 09, 2012 3:53 pm

Re: SOAP Request

Post by freddyp »

USE PROMISES!

During the advanced webinar session (there is on Nov. 17th at 9am and one on Nov. 19th at 4pm) I will explain in a bit more detail why you should use promises instead of callbacks, and offer a strategy or two on how to cope with that.
Post Reply