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
| Name | What it is |
|---|---|
call | Call an operation and return its result element. |
connect | A client for a SOAP endpoint. |
contentType | The Content-Type of a message. |
envelope | Write an envelope. |
faultElement | The Fault element of a version. |
faultEnvelope | Write a fault envelope. |
handle | Answer a request body with handler, as handleWith with no header blocks understood. |
handleWith | Answer a request body with handler, transport-agnostic, as the ultimate receiver. |
isFault | Whether an envelope is a fault. |
operation | An operation element with one text child per parameter, the shape of a document/literal wrapped or RPC requ... |
parse | Decode an envelope of either version. |
parseFault | Read the fault of an envelope. |
parseWsdl | Read a WSDL 1.1 description that imports no other WSDL document. |
parseWsdlWith | Read a WSDL 1.1 description and the WSDL documents it imports. |
requestAction | The SOAPAction of a received request: the SOAPAction header (1.1), else the action parameter of the... |
send | Post an envelope and decode the reply, a fault included. |
senderFault | Throw from a handle handler to answer with a Client (1.1) / Sender (1.2) fault: the request was wrong, an... |
values | The children of an element by local name: each one's text, or its XML when it holds elements. |
withBasicAuth | Authenticate with a user name and password (HTTP Basic). |
withCA | Trust a certificate (PEM) instead of the system roots. |
withDigestAuth | Authenticate with HTTP Digest (RFC 7616): each call goes out without credentials and answers the endpoint's... |
withHeader | Send an HTTP header with every call, replacing one of the same name in any letter case. |
withMaxBytes | Set the response-body cap. |
withSkipVerify | Accept any certificate. |
withSoapHeader | Send a header block with every call, such as a WS-Security or session header. |
withTimeout | Set the idle timeout of each call. |
withToken | Authenticate with a bearer token. |
withVersion | Speak SOAP 1.1 or 1.2. |
wsdlCall | The first SOAP port that offers an operation, with the operation. |
wsdlCallAt | An operation at a named port (the first port of that name, in any service); "" for the first SOAP port that... |
wsdlCallTo | An operation from the first SOAP binding that has it, sent to address: for a description with no... |
wsdlConnect | A client for an operation's endpoint, speaking its SOAP version. |
wsdlRequest | The request body of an operation with one text child per parameter: for document/literal the part's element... |
Client | struct: A SOAP endpoint and how to reach it. |
DigestCredentials | struct: The user and password a Client answers an HTTP Digest challenge with. |
Envelope | struct: A decoded envelope. |
Fault | struct: A SOAP fault, as parseFault reads it and faultEnvelope writes it, for either version. |
Reply | struct: The outcome of send. |
Request | struct: A request as handle passes it to the handler. |
Response | struct: What handle answers: send it as the HTTP response. |
SoapError | struct: A failed SOAP operation. |
Wsdl | struct: A WSDL 1.1 description with its imports: the SOAP ports and bindings. |
WsdlBinding | struct: A SOAP binding: the operations of one port type over SOAP 1.1 or 1.2. |
WsdlCall | struct: One operation at one endpoint: what wsdlConnect, wsdlRequest and call need. |
WsdlOperation | struct: An operation of a SOAP binding, with the parts of its messages. |
WsdlOptions | struct: What parseWsdlWith reads besides the WSDL. |
WsdlPart | struct: One part of a WSDL message: the schema element (document style) or type (rpc style) it carries. |
WsdlPort | struct: A port of a service: an endpoint address over a SOAP binding. |
| constants | the module's constants |
Functions
call
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, withisFaultand the parsedfault), an empty reply Body, or assend
connect
soap.connect(endpoint as string)A client for a SOAP endpoint.
endpoint- the
http://orhttps://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 (usewithBasicAuth), a fragment or a control character
contentType
soap.contentType(version as string, action as string)The Content-Type of a message.
version1.1or1.2action- the SOAPAction; carried here only for 1.2, "" for none
- Returns
string text/xml; charset=utf-8(1.1) orapplication/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
soap.envelope(
version as string,
headers as list of xml.Value,
body as list of xml.Value)Write an envelope.
version1.1or1.2headers- 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
soap.faultElement(version as string, f as Fault)The Fault element of a version.
version1.1or1.2f- the fault;
codeis required,reasonshould 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 pastxml's decoding caps)
faultEnvelope
soap.faultEnvelope(version as string, f as Fault)Write a fault envelope.
version1.1or1.2f- the fault
- Returns
string - the document
- Throws
SoapError - kind
"soap"asfaultElement
handle
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) handlerfunc(req as Request)returning the result element- Returns
Response - the response to send
handleWith
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) handlerfunc(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
soap.isFault(env as Envelope)Whether an envelope is a fault.
env- the envelope
- Returns
bool - whether its Body holds one
Fault
operation
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
nstoo (the schema'selementFormDefault="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
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.2Envelope, a missing or repeatedBody, aHeaderthat is not the first element or holds a block in no namespace, text directly in the Envelope or Body, or aFaultwith other elements beside it - Throws
Error - kind
"limit"for a document pastxml's decoding caps
parseFault
soap.parseFault(env as Envelope)Read the fault of an envelope.
env- an envelope for which
isFaultholds - Returns
Fault - the fault
- Throws
SoapError - kind
"soap"when the envelope is no fault, or a 1.2 fault lacks itsCode
parseWsdl
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"asparseWsdlWith, and for anywsdl:import - Throws
Error - kind
"limit"for a document pastxml's decoding caps
parseWsdlWith
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.1definitions(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 ino.imports, or amaxDocumentsbelow 0 or aboveMAX_WSDL_DOCUMENTS - Throws
Error - kind
"limit"pastmaxDocumentsdocuments orxml's decoding caps
requestAction
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-Typeheader; "" when absent soapAction- the
SOAPActionheader; "" when absent - Returns
string - the action; "" for none
send
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;
isFaultandfaultreport a fault - Throws
Error - kind
"limit"for a reply overmaxBytesor pastxml'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), ashttpthrows 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 (anAuthorizationheader or Digest) for anhttp://endpoint on a non-loopback host withoutallowInsecureHttp
senderFault
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
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
callreturns - Returns
map of string to string - local name to content
withBasicAuth
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
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
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
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
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
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
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
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
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
soap.withVersion(c as Client, version as string)Speak SOAP 1.1 or 1.2.
c- the client
version1.1or1.2- Returns
Client - the changed copy
- Throws
SoapError - kind
"soap"on another version
wsdlCall
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
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
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
soap.wsdlConnect(target as WsdlCall)A client for an operation's endpoint, speaking its SOAP version.
target- the operation, from
wsdlCall - Returns
Client connectto the address, withwithVersion- Throws
SoapError - kind
"soap"asconnect
wsdlRequest
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
callwith 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 parameteroperationrefuses
Structs
Client
A SOAP endpoint and how to reach it. Value-semantic: the with* functions return a changed copy.
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
version1.1or1.2headers- 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
Authorizationheader fromwithHeader) over plainhttp://to a non-loopback host (default false)
DigestCredentials
The user and password a Client answers an HTTP Digest challenge with.
def struct DigestCredentials {
user as string,
password as string
};user- the user name; "" for no Digest auth
password- the password
Envelope
A decoded envelope.
def struct Envelope {
version as string,
headers as list of xml.Value,
body as list of xml.Value
};version1.1or1.2headers- the header blocks (the
Header's children) body- the
Body's children: the operation or result element, or oneFault
Fault
A SOAP fault, as parseFault reads it and faultEnvelope writes it, for either version.
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 asClient.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
Subcodevalue, as{ns}localor a bare name; "" for none and for 1.1 reasonfaultstring(1.1) or the firstReason/Text(1.2)actorfaultactor(1.1) orRole(1.2); "" for nonedetail- 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.
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.
def struct Request {
version as string,
action as string,
headers as list of xml.Value,
body as xml.Value
};version1.1or1.2action- 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.
def struct Response {
status as int,
contentType as string,
body as string
};status- 200, or 400 / 500 for a fault
contentType- the
Content-Typeheader 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.
def struct SoapError {
kind as string,
message as string,
status as int,
isFault as bool,
fault as Fault
};kind- always
"soap"(ERROR_KIND) messagesoap:and what failed (soap: fault CODE: REASONfor 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.
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.
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
version1.1or1.2style- the binding's default style,
documentorrpc operations- in document order
WsdlCall
One operation at one endpoint: what wsdlConnect, wsdlRequest and call need.
def struct WsdlCall {
address as string,
version as string,
operation as WsdlOperation
};address- the endpoint URL
version1.1or1.2operation- the operation
WsdlOperation
An operation of a SOAP binding, with the parts of its messages.
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
styledocumentorrpcbodyUseliteralorencoded(the input'ssoap: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 partsnames 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.
def struct WsdlOptions {
imports as map of string to string,
maxDocuments as int
};importswsdl:importlocation to that document's text, read by the callermaxDocuments- 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.
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
elementNamespacesetselementFormDefault="qualified"(thequalifiedargument ofoperation)
WsdlPort
A port of a service: an endpoint address over a SOAP binding.
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) version1.1or1.2binding- 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
kindof every error the module throws. soap.FAULT_KIND as string- The
kindof an error ahandlehandler throws (seesenderFault) to answer with a Client (1.1) / Sender (1.2) fault carrying its message. soap.MAX_WSDL_DOCUMENTS as int- How many documents one
parseWsdlWithreads: 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.