Skip to content

Instantly share code, notes, and snippets.

@stanwu
Created October 31, 2022 06:34
Show Gist options
  • Save stanwu/f29d50baacb028b39cdc2d224f27fbfc to your computer and use it in GitHub Desktop.
Save stanwu/f29d50baacb028b39cdc2d224f27fbfc to your computer and use it in GitHub Desktop.
wsdlRequest.js
async function wsdlRequest(wsdlUrl, method, auth, req) {
return new Promise((resolve, reject) => {
const res = {};
soap.createClient(wsdlUrl, function(err, client) {
if (auth.username === undefined) {
reject('No username specified');
}
if (auth.password === undefined) {
reject('No password specified');
}
const wsSecurity = new soap.WSSecurity(auth.username, auth.password)
client.setSecurity(wsSecurity);
client.on('response', responseXml => {
res.responseXml = responseXml;
});
let clientMethod = client[method];
if (method === 'PickUpRequest') {
clientMethod = clientMethod.euExpressRateBook_providerServices_PickUpRequest_Port.PickUpRequest;
}
clientMethod(req, function(err, response) {
const requestXml = format(client.lastRequest).replace(auth.password, '**********');
if (err) {
err.requestXml = requestXml;
reject(err);
} else {
res.requestXml = requestXml;
res.response = response;
resolve(res);
}
});
});
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment