vn-cc-vmp/soapClient.js

61 lines
1.8 KiB
JavaScript
Raw Permalink Normal View History

2017-04-10 08:56:51 +00:00
var querystring = require("querystring");
var xml2js = require('xml2js');
var soap = require('soap');
2017-04-11 08:03:39 +00:00
var IOXml = require('./IOXml');
2017-04-10 09:52:16 +00:00
var config = require('./config.json');
2017-04-10 08:56:51 +00:00
function soapClient(xmlFile){
var url = 'http://services2-acc.floraholland.com/CommercialCustomer/CommercialCustomer_1p5.svc?wsdl';
2017-04-10 09:52:16 +00:00
var auth = "Basic " + new Buffer(config.user + ":" + config.pass).toString("base64");
2017-04-10 08:56:51 +00:00
var options =
{
wsdl_headers:{
Authorization: auth
},
attributesKey: '$',
valueKey: '_'
};
soap.createClient(url,options, function(err, client) {
if (err) {
console.log(err);
return;
}
2017-04-10 09:52:16 +00:00
client.setSecurity(new soap.BasicAuthSecurity(config.user,config.pass));
2017-04-10 08:56:51 +00:00
console.log('no entra');
2017-04-11 08:03:39 +00:00
IOXml.getXml(xmlFile, function(err, data) {
2017-04-10 08:56:51 +00:00
if (err) {
console.log('err');
console.log(err);
return;
}
var parser = new xml2js.Parser();
parser.parseString(data, function (err, result) {
//extractedData = result['config']['data'];
console.dir(result,{
showHidden:true,
depth:null,
colors:true
});
console.log('GetSupply');
console.log(result);
console.log(result.SupplyRequest);
client.GetSupply(result.SupplyRequest,function(err, supply) {
console.log('last request: ', client.lastRequest)
if (err) {
console.log(err.message);
return;
}
2017-04-11 08:03:39 +00:00
var builder = new xml2js.Builder();
var fileContent = builder.buildObject(supply);
IOXml.setXml('/xml_buyer/supplyresponse_getall.xml',fileContent,function(){
console.log('archivo creado');
});
2017-04-10 08:56:51 +00:00
});
});
});
});
}
soapClient('/xml_buyer/supplyrequest_getall.xml');