Skip to content
Jennifer Programming Language

soap API reference

SOAP 1.1 and 1.2 over HTTP: a client that calls an operation and returns its result element, and a transport-agnostic server dispatcher.

The protocol layer (envelope, parse, Fault, parseFault, faultEnvelope) knows nothing about sockets. The client posts envelopes over http; the server side, handle, turns a request body into a reply body for any transport, such as an httpd loop. Payloads are xml.Value elements: build them with operation or the xml builders and read them with values or the xml accessors. parseWsdl reads a WSDL 1.1 description's ports, bindings and operations (SOAPAction, style, message parts), and wsdlCall / wsdlConnect / wsdlRequest turn one operation into a client and a request body; schema types are not read. Needs the default jennifer binary (net via http).

Import with import "soap.j" as soap;. See the soap guide for prose and examples.

Contents

NameWhat it is
callCall an operation and return its result element.
connectA client for a SOAP endpoint.
contentTypeThe Content-Type of a message.
envelopeWrite an envelope.
faultElementThe Fault element of a version.
faultEnvelopeWrite a fault envelope.
handleAnswer a request body with handler, as handleWith with no header blocks understood.
handleWithAnswer a request body with handler, transport-agnostic, as the ultimate receiver.
isFaultWhether an envelope is a fault.
operationAn operation element with one text child per parameter, the shape of a document/literal wrapped or RPC requ...
parseDecode an envelope of either version.
parseFaultRead the fault of an envelope.
parseWsdlRead a WSDL 1.1 description that imports no other WSDL document.
parseWsdlWithRead a WSDL 1.1 description and the WSDL documents it imports.
requestActionThe SOAPAction of a received request: the SOAPAction header (1.1), else the action parameter of the...
sendPost an envelope and decode the reply, a fault included.
senderFaultThrow from a handle handler to answer with a Client (1.1) / Sender (1.2) fault: the request was wrong, an...
valuesThe children of an element by local name: each one's text, or its XML when it holds elements.
withBasicAuthAuthenticate with a user name and password (HTTP Basic).
withCATrust a certificate (PEM) instead of the system roots.
withDigestAuthAuthenticate with HTTP Digest (RFC 7616): each call goes out without credentials and answers the endpoint's...
withHeaderSend an HTTP header with every call, replacing one of the same name in any letter case.
withMaxBytesSet the response-body cap.
withSkipVerifyAccept any certificate.
withSoapHeaderSend a header block with every call, such as a WS-Security or session header.
withTimeoutSet the idle timeout of each call.
withTokenAuthenticate with a bearer token.
withVersionSpeak SOAP 1.1 or 1.2.
wsdlCallThe first SOAP port that offers an operation, with the operation.
wsdlCallAtAn operation at a named port (the first port of that name, in any service); "" for the first SOAP port that...
wsdlCallToAn operation from the first SOAP binding that has it, sent to address: for a description with no...
wsdlConnectA client for an operation's endpoint, speaking its SOAP version.
wsdlRequestThe request body of an operation with one text child per parameter: for document/literal the part's element...
Clientstruct: A SOAP endpoint and how to reach it.
DigestCredentialsstruct: The user and password a Client answers an HTTP Digest challenge with.
Envelopestruct: A decoded envelope.
Faultstruct: A SOAP fault, as parseFault reads it and faultEnvelope writes it, for either version.
Replystruct: The outcome of send.
Requeststruct: A request as handle passes it to the handler.
Responsestruct: What handle answers: send it as the HTTP response.
SoapErrorstruct: A failed SOAP operation.
Wsdlstruct: A WSDL 1.1 description with its imports: the SOAP ports and bindings.
WsdlBindingstruct: A SOAP binding: the operations of one port type over SOAP 1.1 or 1.2.
WsdlCallstruct: One operation at one endpoint: what wsdlConnect, wsdlRequest and call need.
WsdlOperationstruct: An operation of a SOAP binding, with the parts of its messages.
WsdlOptionsstruct: What parseWsdlWith reads besides the WSDL.
WsdlPartstruct: One part of a WSDL message: the schema element (document style) or type (rpc style) it carries.
WsdlPortstruct: A port of a service: an endpoint address over a SOAP binding.
constantsthe module's constants

Functions

call

jennifer
soap.call(c as Client, action as string, body as xml.Value)

Call an operation and return its result element.

c
the client
action
the SOAPAction URI from the WSDL; "" for none
body
the operation element (see operation)
Returns xml.Value
the reply's first Body child, e.g. AddResponse
Throws SoapError
kind "soap" on a fault (soap: fault CODE: REASON, with isFault and the parsed fault), an empty reply Body, or as send

connect

jennifer
soap.connect(endpoint as string)

A client for a SOAP endpoint.

endpoint
the http:// or https:// service URL
Returns Client
SOAP 1.1, 30 s idle timeout, 16 MiB response cap, full certificate checking
Throws SoapError
kind "soap" on a URL that is not http(s), or carries credentials (use withBasicAuth), a fragment or a control character

contentType

jennifer
soap.contentType(version as string, action as string)

The Content-Type of a message.

version
1.1 or 1.2
action
the SOAPAction; carried here only for 1.2, "" for none
Returns string
text/xml; charset=utf-8 (1.1) or application/soap+xml; charset=utf-8[; action="..."] (1.2)
Throws SoapError
kind "soap" on an unknown version, or an action with a quote, backslash or control character

envelope

jennifer
soap.envelope(
    version as string,
    headers as list of xml.Value,
    body as list of xml.Value)

Write an envelope.

version
1.1 or 1.2
headers
header blocks; [] for no Header
body
the Body's children, usually one
Returns string
the document, with an XML declaration
Throws SoapError
kind "soap" on an unknown version

faultElement

jennifer
soap.faultElement(version as string, f as Fault)

The Fault element of a version.

version
1.1 or 1.2
f
the fault; code is required, reason should be set. Characters XML 1.0 does not allow are written as ?
Returns xml.Value
the element, for an envelope's Body
Throws SoapError
kind "soap" on an unknown version, a malformed code (one in a reserved namespace or a namespace with a control character included), a 1.2 code that is not a standard one, or a detail starting with < that is not XML (kind "limit" for one past xml's decoding caps)

faultEnvelope

jennifer
soap.faultEnvelope(version as string, f as Fault)

Write a fault envelope.

version
1.1 or 1.2
f
the fault
Returns string
the document
Throws SoapError
kind "soap" as faultElement

handle

jennifer
soap.handle(body as string, action as string, handler as func)

Answer a request body with handler, as handleWith with no header blocks understood.

body
the HTTP request body
action
the SOAPAction (see requestAction)
handler
func(req as Request) returning the result element
Returns Response
the response to send

handleWith

jennifer
soap.handleWith(
    body as string,
    action as string,
    handler as func,
    understood as list of string)

Answer a request body with handler, transport-agnostic, as the ultimate receiver. Malformed XML or a Body without exactly one element is a Client / Sender fault; an envelope in another namespace is a VersionMismatch fault; a header block for this node (see mustUnderstand) with mustUnderstand set whose Clark name is not in understood is a MustUnderstand fault. The handler's result is sent in the request's version; for its errors see senderFault. Cap the request body in the transport.

body
the HTTP request body
action
the SOAPAction (see requestAction)
handler
func(req as Request) returning the result element (xml.Value)
understood
the header blocks the handler processes, by Clark name ({ns}local)
Returns Response
the response to send; status 200, or 400 / 500 for a fault

isFault

jennifer
soap.isFault(env as Envelope)

Whether an envelope is a fault.

env
the envelope
Returns bool
whether its Body holds one Fault

operation

jennifer
soap.operation(
    ns as string,
    name as string,
    params as map of string to string,
    qualified as bool)

An operation element with one text child per parameter, the shape of a document/literal wrapped or RPC request.

ns
the operation's namespace, e.g. http://tempuri.org/
name
the operation, e.g. Add
params
child name to text, in order
qualified
put the children in ns too (the schema's elementFormDefault="qualified", as .NET services expect); false leaves them unqualified (the JAX-WS default)
Returns xml.Value
the element, e.g. <m:Add xmlns:m="..."><m:intA>2</m:intA>...
Throws SoapError
kind "soap" on an empty or reserved (xml, xmlns) namespace or one with a control character, a name that is not an XML name, or a value with a character XML 1.0 does not allow

parse

jennifer
soap.parse(text as string)

Decode an envelope of either version.

text
the document
Returns Envelope
the envelope
Throws SoapError
kind "soap" on malformed XML, a DOCTYPE, a root that is not a 1.1 or 1.2 Envelope, a missing or repeated Body, a Header that is not the first element or holds a block in no namespace, text directly in the Envelope or Body, or a Fault with other elements beside it
Throws Error
kind "limit" for a document past xml's decoding caps

parseFault

jennifer
soap.parseFault(env as Envelope)

Read the fault of an envelope.

env
an envelope for which isFault holds
Returns Fault
the fault
Throws SoapError
kind "soap" when the envelope is no fault, or a 1.2 fault lacks its Code

parseWsdl

jennifer
soap.parseWsdl(text as string)

Read a WSDL 1.1 description that imports no other WSDL document.

text
the WSDL document
Returns Wsdl
its SOAP ports and bindings
Throws SoapError
kind "soap" as parseWsdlWith, and for any wsdl:import
Throws Error
kind "limit" for a document past xml's decoding caps

parseWsdlWith

jennifer
soap.parseWsdlWith(text as string, o as WsdlOptions)

Read a WSDL 1.1 description and the WSDL documents it imports. Nothing is fetched: o.imports maps each wsdl:import location to that document's text, read by the caller. An import of an import is looked up in the same map; each location, and each document text, is read once, so an import back to the importing document is no error. XML Schema imports (xs:import) are not followed: the parts name their elements and types, not their contents.

text
the WSDL document
o
the imported documents and the document cap
Returns Wsdl
the SOAP ports and bindings of all the documents
Throws SoapError
kind "soap" on malformed XML, a DOCTYPE, a root that is not WSDL 1.1 definitions (WSDL 2.0 is refused by name), a missing or malformed required attribute, an undeclared prefix, a name defined twice, an overloaded operation, a reference to an undefined message, port type or binding, a style other than document or rpc, an import not in o.imports, or a maxDocuments below 0 or above MAX_WSDL_DOCUMENTS
Throws Error
kind "limit" past maxDocuments documents or xml's decoding caps

requestAction

jennifer
soap.requestAction(contentType as string, soapAction as string)

The SOAPAction of a received request: the SOAPAction header (1.1), else the action parameter of the Content-Type (1.2), unquoted.

contentType
the Content-Type header; "" when absent
soapAction
the SOAPAction header; "" when absent
Returns string
the action; "" for none

send

jennifer
soap.send(c as Client, action as string, body as xml.Value)

Post an envelope and decode the reply, a fault included.

c
the client
action
the SOAPAction URI from the WSDL; "" for none
body
the operation element
Returns Reply
the reply; isFault and fault report a fault
Throws Error
kind "limit" for a reply over maxBytes or past xml's decoding caps, "timeout" when the server does not answer in time, "closed" when it closes the connection under the call (soap: POST <endpoint>: ...)
Throws net.NetError
kind "net" on a socket failure (refused, reset, DNS, TLS), as http throws it
Throws SoapError
kind "soap" on another transport error, a reply that is not an envelope (with the HTTP status when it is not 2xx), a non-fault reply in the other SOAP version, a non-2xx status without a fault, or (before connecting, status 0) credentials (an Authorization header or Digest) for an http:// endpoint on a non-loopback host without allowInsecureHttp

senderFault

jennifer
soap.senderFault(reason as string)

Throw from a handle handler to answer with a Client (1.1) / Sender (1.2) fault: the request was wrong, and reason says how. Any other error a handler throws becomes a Server / Receiver fault with a generic reason, so internal messages do not reach the caller.

reason
the fault reason

values

jennifer
soap.values(node as xml.Value)

The children of an element by local name: each one's text, or its XML when it holds elements. Of repeated names the first wins; read a repeated or nested result with the xml accessors.

node
e.g. the result element call returns
Returns map of string to string
local name to content

withBasicAuth

jennifer
soap.withBasicAuth(c as Client, user as string, password as string)

Authenticate with a user name and password (HTTP Basic). Over http:// they would travel readable, so a call to an http:// endpoint on a non-loopback host throws unless the client's allowInsecureHttp is set.

c
the client
user
the user name, without :
password
the password
Returns Client
the changed copy
Throws SoapError
kind "soap" on a : in the name or a control character

withCA

jennifer
soap.withCA(c as Client, pem as bytes)

Trust a certificate (PEM) instead of the system roots.

c
the client
pem
the certificate
Returns Client
the changed copy

withDigestAuth

jennifer
soap.withDigestAuth(c as Client, user as string, password as string)

Authenticate with HTTP Digest (RFC 7616): each call goes out without credentials and answers the endpoint's 401 challenge (http.sendDigest), so it costs one extra round trip. Replaces Basic or bearer auth set before; withBasicAuth / withToken replace it in turn. A listener can crack the response offline, so over http:// it is refused as Basic is (see withBasicAuth).

c
the client
user
the user name
password
the password
Returns Client
the changed copy
Throws SoapError
kind "soap" on an empty user name or a control character in it

withHeader

jennifer
soap.withHeader(c as Client, name as string, value as string)

Send an HTTP header with every call, replacing one of the same name in any letter case.

c
the client
name
the header name
value
its value
Returns Client
the changed copy
Throws SoapError
kind "soap" on a bad name, a value with a control character, or a header the client sets itself (Content-Type, SOAPAction, Host, Content-Length, ...)

withMaxBytes

jennifer
soap.withMaxBytes(c as Client, n as int)

Set the response-body cap. A decoded reply takes up to about 15 times its size in memory.

c
the client
n
bytes; 0 or less for the default, 16 MiB
Returns Client
the changed copy

withSkipVerify

jennifer
soap.withSkipVerify(c as Client)

Accept any certificate. The connection stays encrypted but is no longer authenticated; prefer withCA.

c
the client
Returns Client
the changed copy

withSoapHeader

jennifer
soap.withSoapHeader(c as Client, block as xml.Value)

Send a header block with every call, such as a WS-Security or session header. Add a mustUnderstand attribute yourself where the service needs one.

c
the client
block
the header block, a namespaced element
Returns Client
the changed copy
Throws SoapError
kind "soap" on a text node or an element without namespace, which SOAP does not allow as a header block

withTimeout

jennifer
soap.withTimeout(c as Client, ms as int)

Set the idle timeout of each call.

c
the client
ms
milliseconds; 0 or less for the default, 30 s
Returns Client
the changed copy

withToken

jennifer
soap.withToken(c as Client, token as string)

Authenticate with a bearer token.

c
the client
token
the token
Returns Client
the changed copy
Throws SoapError
kind "soap" on an empty token or one with a space or control character

withVersion

jennifer
soap.withVersion(c as Client, version as string)

Speak SOAP 1.1 or 1.2.

c
the client
version
1.1 or 1.2
Returns Client
the changed copy
Throws SoapError
kind "soap" on another version

wsdlCall

jennifer
soap.wsdlCall(w as Wsdl, name as string)

The first SOAP port that offers an operation, with the operation.

w
the description
name
the operation's name
Returns WsdlCall
its address, version and operation
Throws SoapError
kind "soap" when no SOAP port offers it

wsdlCallAt

jennifer
soap.wsdlCallAt(w as Wsdl, port as string, name as string)

An operation at a named port (the first port of that name, in any service); "" for the first SOAP port that offers it.

w
the description
port
the port's name, or ""
name
the operation's name
Returns WsdlCall
its address, version and operation
Throws SoapError
kind "soap" on an unknown port, or when no matching port offers the operation

wsdlCallTo

jennifer
soap.wsdlCallTo(w as Wsdl, address as string, name as string)

An operation from the first SOAP binding that has it, sent to address: for a description with no service (ONVIF's device WSDLs, whose address comes from discovery) or whose ports name another host.

w
the description
address
the endpoint URL
name
the operation's name
Returns WsdlCall
the address, the binding's version and the operation
Throws SoapError
kind "soap" when no SOAP binding has the operation

wsdlConnect

jennifer
soap.wsdlConnect(target as WsdlCall)

A client for an operation's endpoint, speaking its SOAP version.

target
the operation, from wsdlCall
Returns Client
connect to the address, with withVersion
Throws SoapError
kind "soap" as connect

wsdlRequest

jennifer
soap.wsdlRequest(target as WsdlCall, params as map of string to string)

The request body of an operation with one text child per parameter: for document/literal the part's element (children qualified as its schema says), for rpc/literal a wrapper named after the operation in the soap:body namespace. Build any other shape with the xml builders.

target
the operation, from wsdlCall
params
child name to text, in order
Returns xml.Value
the body element, for call with the operation's action
Throws SoapError
kind "soap" for an encoded operation, an rpc operation without a namespace, a document operation whose input is not one element part, or a parameter operation refuses

Structs

Client

A SOAP endpoint and how to reach it. Value-semantic: the with* functions return a changed copy.

jennifer
def struct Client {
    endpoint as string,
    version as string,
    headers as map of string to string,
    soapHeaders as list of xml.Value,
    tls as http.TlsOptions,
    timeoutMs as int,
    maxBytes as int,
    digest as DigestCredentials,
    allowInsecureHttp as bool
};
endpoint
the service URL
version
1.1 or 1.2
headers
HTTP headers sent with every call
soapHeaders
header blocks sent with every call
tls
certificate checking
timeoutMs
the idle timeout of each call
maxBytes
the response-body cap
digest
HTTP Digest credentials (withDigestAuth); an empty user for none
allowInsecureHttp
allow credentials (Basic, bearer, Digest, an Authorization header from withHeader) over plain http:// to a non-loopback host (default false)

DigestCredentials

The user and password a Client answers an HTTP Digest challenge with.

jennifer
def struct DigestCredentials {
    user as string,
    password as string
};
user
the user name; "" for no Digest auth
password
the password

Envelope

A decoded envelope.

jennifer
def struct Envelope {
    version as string,
    headers as list of xml.Value,
    body as list of xml.Value
};
version
1.1 or 1.2
headers
the header blocks (the Header's children)
body
the Body's children: the operation or result element, or one Fault

Fault

A SOAP fault, as parseFault reads it and faultEnvelope writes it, for either version.

jennifer
def struct Fault {
    code as string,
    subcode as string,
    reason as string,
    actor as string,
    detail as string
};
code
a code of the envelope namespace without prefix: VersionMismatch, MustUnderstand, Client / Server (1.1, also dotted as Client.Auth), Sender / Receiver / DataEncodingUnknown (1.2). Otherwise (1.1 only) a code in another namespace as {ns}local, or one in no namespace as written
subcode
the first 1.2 Subcode value, as {ns}local or a bare name; "" for none and for 1.1
reason
faultstring (1.1) or the first Reason/Text (1.2)
actor
faultactor (1.1) or Role (1.2); "" for none
detail
the detail's content: its XML when it holds elements (text mixed in written in place), else its text; "" for none. Read from a detail that mixes text with elements, it is the whole detail element

Reply

The outcome of send.

jennifer
def struct Reply {
    status as int,
    envelope as Envelope,
    isFault as bool,
    fault as Fault
};
status
the HTTP status
envelope
the reply; an empty body for a bodiless 2xx (a one-way operation)
isFault
whether the reply is a fault
fault
the fault when isFault

Request

A request as handle passes it to the handler.

jennifer
def struct Request {
    version as string,
    action as string,
    headers as list of xml.Value,
    body as xml.Value
};
version
1.1 or 1.2
action
the SOAPAction, as given to handle
headers
the header blocks
body
the operation element (the Body's one child)

Response

What handle answers: send it as the HTTP response.

jennifer
def struct Response {
    status as int,
    contentType as string,
    body as string
};
status
200, or 400 / 500 for a fault
contentType
the Content-Type header
body
the envelope

SoapError

A failed SOAP operation. Every error of kind "soap" is one, so its fields are safe to read once the kind matches. call throws it on a fault, with the parsed fault; send returns a fault instead of throwing.

jennifer
def struct SoapError {
    kind as string,
    message as string,
    status as int,
    isFault as bool,
    fault as Fault
};
kind
always "soap" (ERROR_KIND)
message
soap: and what failed (soap: fault CODE: REASON for a fault)
status
the HTTP status of the reply; 0 when there was none (a malformed message, a local check, a transport failure)
isFault
whether the server answered with a SOAP fault
fault
the fault when isFault; empty fields otherwise

Wsdl

A WSDL 1.1 description with its imports: the SOAP ports and bindings. Bindings and ports of other kinds (HTTP GET/POST, MIME) are left out.

jennifer
def struct Wsdl {
    name as string,
    targetNamespace as string,
    ports as list of WsdlPort,
    bindings as list of WsdlBinding
};
name
the definitions' name; "" when unset
targetNamespace
the definitions' target namespace
ports
every SOAP port, in document order
bindings
every SOAP binding

WsdlBinding

A SOAP binding: the operations of one port type over SOAP 1.1 or 1.2.

jennifer
def struct WsdlBinding {
    name as string,
    namespace as string,
    version as string,
    style as string,
    operations as list of WsdlOperation
};
name
the binding's name
namespace
the target namespace it is defined in
version
1.1 or 1.2
style
the binding's default style, document or rpc
operations
in document order

WsdlCall

One operation at one endpoint: what wsdlConnect, wsdlRequest and call need.

jennifer
def struct WsdlCall {
    address as string,
    version as string,
    operation as WsdlOperation
};
address
the endpoint URL
version
1.1 or 1.2
operation
the operation

WsdlOperation

An operation of a SOAP binding, with the parts of its messages.

jennifer
def struct WsdlOperation {
    name as string,
    action as string,
    style as string,
    bodyUse as string,
    namespace as string,
    input as list of WsdlPart,
    output as list of WsdlPart,
    inputHeaders as list of WsdlPart,
    outputHeaders as list of WsdlPart
};
name
the operation's name
action
the SOAPAction; "" when the binding sets none
style
document or rpc
bodyUse
literal or encoded (the input's soap:body use)
namespace
the rpc wrapper's namespace (soap:body namespace); "" for document style
input
the parts of the request Body: the input message's parts, or those its soap:body parts names
output
the parts of the response Body, as input; [] when one-way
inputHeaders
the request's header blocks (soap:header), in order
outputHeaders
the response's header blocks

WsdlOptions

What parseWsdlWith reads besides the WSDL. The zero value reads no import and keeps the default document cap.

jennifer
def struct WsdlOptions {
    imports as map of string to string,
    maxDocuments as int
};
imports
wsdl:import location to that document's text, read by the caller
maxDocuments
documents read at most, the WSDL included: 0 is MAX_WSDL_DOCUMENTS, which a value may only lower

WsdlPart

One part of a WSDL message: the schema element (document style) or type (rpc style) it carries.

jennifer
def struct WsdlPart {
    name as string,
    elementNamespace as string,
    element as string,
    typeNamespace as string,
    typeName as string,
    qualified as bool
};
name
the part's name
elementNamespace
the namespace of element; "" with a type
element
the element's local name; "" when the part names a type
typeNamespace
the namespace of typeName; "" with an element
typeName
the type's local name; "" when the part names an element
qualified
an inline schema for elementNamespace sets elementFormDefault="qualified" (the qualified argument of operation)

WsdlPort

A port of a service: an endpoint address over a SOAP binding.

jennifer
def struct WsdlPort {
    service as string,
    name as string,
    address as string,
    version as string,
    binding as string,
    bindingNamespace as string
};
service
the service it belongs to
name
the port's name
address
the endpoint URL (soap:address location)
version
1.1 or 1.2
binding
the binding's name
bindingNamespace
the binding's namespace

Constants

soap.DEFAULT_MAX_BYTES as int
The response-body cap a Client starts with: 16 MiB.
soap.ERROR_KIND as string
The kind of every error the module throws.
soap.FAULT_KIND as string
The kind of an error a handle handler throws (see senderFault) to answer with a Client (1.1) / Sender (1.2) fault carrying its message.
soap.MAX_WSDL_DOCUMENTS as int
How many documents one parseWsdlWith reads: the WSDL and its imports.
soap.SOAP11_NS as string
The SOAP 1.1 envelope namespace.
soap.SOAP12_NS as string
The SOAP 1.2 envelope namespace.
soap.WSDL_NS as string
The WSDL 1.1 namespace.