Skip to content

Use Case: Implement a SOAP Web Service

do- edited this page Dec 11, 2022 · 14 revisions

Input

You have:

  • a WSDL file myService.wsdl stored in a local filesystem with all dependencies;
  • a function named myMethod (rq) that calculates a response for any given HTTP request:
    • normally, the output is a single property object {MyMethodResponse: {...}}, where MyMethodResponse is a local name of the element representing the corresponding message type;
    • otherwise, an Error is thrown.

Problem

Send the HTTP response rp representing the obtained result as a SOAP message.

Solution outline

const {XMLSchemata, SOAP11, SOAPFault} = require ('xml-toolkit')

const xs = new XMLSchemata (`myService.wsdl`)

let body, statusCode

try {  
  body = xs.stringify (myMethod (rq))

  statusCode
}
catch (x) {
  body = new SOAPFault (x)
}

Clone this wiki locally