Created
May 31, 2019 06:45
-
-
Save liudonghua123/3d96acab29ce8d627feeb9c8858a38ea to your computer and use it in GitHub Desktop.
A simple node app for soap operation demonstration
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
const getCircularReplacer = () => { | |
const seen = new WeakSet(); | |
return (key, value) => { | |
if (typeof value === "object" && value !== null) { | |
if (seen.has(value)) { | |
return; | |
} | |
seen.add(value); | |
} | |
return value; | |
}; | |
}; | |
const fs = require("fs"); | |
const soap = require('soap'); | |
const xml2js = require('xml2js'); | |
const parser = new xml2js.Parser(); | |
(async () => { | |
const url = 'https://graphical.weather.gov/xml/DWMLgen/wsdl/ndfdXML.wsdl'; | |
let args = {LatLonListZipCode: 75001}; | |
const client = await soap.createClientAsync(url); | |
//client.describe(); | |
//console.info(`client: ${JSON.stringify(client, getCircularReplacer(), 2)}`); | |
// fs.writeFile("temp.txt", JSON.stringify(client, getCircularReplacer(), 2), (err) => { | |
// if (err) console.log(err); | |
// console.log("Successfully Written to File."); | |
// }); | |
const [result] = await client.LatLonListZipCodeAsync(args); | |
console.log(`result: ${JSON.stringify(result, getCircularReplacer(), 2)}`); | |
parser.parseString(result.listLatLonOut.$value, (err, result) => { | |
console.dir(err); | |
console.dir(result.dwml.latLonList); | |
}) | |
})() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Another way for making soap request using
strong-soap
But the result also have to transform, the
XMLHandler
seems not enough.The result of the following code is: