Created
October 31, 2022 06:34
-
-
Save stanwu/f29d50baacb028b39cdc2d224f27fbfc to your computer and use it in GitHub Desktop.
wsdlRequest.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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