-
Notifications
You must be signed in to change notification settings - Fork 5
Use Case: Implement a SOAP Web Service
do- edited this page Dec 11, 2022
·
14 revisions
You have:
- a WSDL file
myService.wsdlstored in a local filesystem with all dependencies; - a function named
myMethod (/*...*/)that calculates:- normally, a single property object
{MyMethodResponse: {...}}, whereMyMethodResponseis a local name of the element representing the corresponding message type; - otherwise, an
Erroris thrown.
- normally, a single property object
Send the HTTP response rp representing the obtained result as a SOAP message.
const {XMLSchemata, SOAP11, SOAP12, SOAPFault} = require ('xml-toolkit')
const SOAP = SOAP11 // or SOAP12
const xs = new XMLSchemata (`myService.wsdl`)
let body, statusCode; try {
body = xs.stringify (myMethod (/*...*/))
statusCode = 200
}
catch (x) {
body = new SOAPFault (x)
statusCode = 500
}
rp.writeHead (statusCode, {
'Content-Type': SOAP.contentType,
})
rp.end (SOAP.message (body))Provide its literal XML as the 2nd argument to SOAP.message
rp.end (SOAP.message (body, header))To add an empty Header element, use the zero length string ('').
For missing or null 2nd argument, SOAP Header is omitted.