Skip to content
do- edited this page Dec 11, 2022 · 2 revisions

SOAP12 is a tool for composing SOAP 1.2 messages from plain data objects according to a given WSDL.

It isn't a complete WS client or server as it hasn't any ability to actually send messages: those tasks are left to the satandard HTTP agent or any of its alternatives.

What SOAP12 do exactly is:

  • composing the SOAP XML text (basically serializing data objects with XMLMarshaller according to the XML Schema).
const http = require ('http')
const {SOAP12} = require ('xml-toolkit')

const soap = new SOAP12 ('their.wsdl')

// Invoking a SOAP 1.2 WS

const {method, headers, body} = soap.http ({RequestElementNameOfTheirs: {amount: '0.01'}})

const rq = http.request (endpointURL, {method, headers})
rq.write (body)

// Generating a WS response

const body = /*...*/, header = /*...*/, encoding = 'cp866'
const msg = SOAP12.message (body, header, {declaration: {encoding}})

Constructor

const soap = new SOAP12 (wsdlFilePath)

This parses the given WSDL file (and its imports recursively) and builds the corresponding XMLSchemata.

Instance Methods

http

const {method, headers, body} = soap.http (requestDataObject)

The given requestDataObject is first serialized XMLSchemata.

Then, it is wrapped in a SOAP 1.2 envelope.

Additionally, the WSDL tree is scanned based on the requestDataObject's only root property name to be found as some message part element local name. If the binding contains an operation using this message, the corresponding SOAPAction is set as an HTTP header.

Finally, the {method, headers, body} object is returned.

Limitations

All WSDL/XSD objects are looked up by local names; namespaces are ignored.

In most real world cases, this causes no problem as local names of elements, messages and operations declared in one WSDL file are usually unique.

There is however no guarantee of any kind here. With WSDL really making use of the XML namespaces feature, the SOAP11 is inapplicable. In that situations, one should use more low level xml-toolkit items (like XMLSchemata) or other software.

The goal here is to provide developers with a minimalistic API helping to do routine work, but not to cover all possible cases allowed by specifications.

Static Members

name value
SOAP12.contentType application/soap+xml

Static Methods

message

const msg = SOAP12.message (body, header, /*{
  declaration: {encoding}
}*/)

/* Result:
<?xml version="1.0" encoding="${encoding}"?>
<ns0:Envelope xmlns:ns0="http://www.w3.org/2003/05/soap-envelope">
  <ns0:Header>${header}</ns0:Header>
  <ns0:Body>${body}</ns0:Body>
</ns0:Envelope>
*/

Parameters

body

Raw SOAP Body contents in one of forms recognized by XMLSchemata.any (), including a plain string.

A SOAPFault instance can be used instead of a String.

header

Raw SOAP Header contents in one of forms recognized by XMLSchemata.any (): including a plain string.

May be null or missing: in that case, the Header element is missing from the Envelope.

stringifyOptions

Options passed to XMLMarshaller.stringify as is. Currently, only the declaration option have sense.