Home > Uncategorized > Call an #ASMX #WebService API using #NodeJS

Call an #ASMX #WebService API using #NodeJS

images

Here’s a quick example showing how to use NodeJS to call an ASMX .NET webservice: – you need to replace the username with one from your account on RegCheck.org.uk

And you need to npm install xml2js

var http = require(‘http’);
var parseString = require(‘xml2js’).parseString; // npm install xml2js

function getHttp(host,path,callback) {

return http.get({
host: host,
path: path
}, function(response) {
// Continuously update stream with data
var body = ”;
response.on(‘data’, function(d) {
body += d;
});
response.on(‘end’, function() {
callback(body);
});
});
}
getHttp(“www.regcheck.org.uk”,”/api/reg.asmx/Check?RegistrationNumber=ukz2955&username=XXXXXXX”,function(data){
parseString(data,function(err,result){
var innerJson = result.Vehicle.vehicleJson;
var oInnerJson = JSON.parse(innerJson);
console.log(oInnerJson.Description);
});
});

Advertisement
Categories: Uncategorized
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: