SOAP backends as JSON APIs¶
How-to guideThe steps for one task.
Many of the services an organization needs to publish are SOAP services: one endpoint, an XML
envelope per call, operations told apart by a SOAPAction header, described by a WSDL. Your
callers work with JSON. The soap policy lets you publish such a backend as an ordinary Apinx
API: the caller sends JSON, the gateway builds the envelope, calls the backend, decodes the XML
answer to JSON and turns a SOAP fault into one of the gateway's own coded errors. Every other
feature, keys, products, rate limits, caching, analytics, the request inspector, applies as on any
API, and the caller never sees XML.
You do the mapping once, one soap policy per operation, in the console or in the gateway file.
A WSDL import creates the API, its operations and a starting mapping for each, so a service with
forty operations is minutes of work rather than an afternoon. The gateway itself does not become a
SOAP server: a caller that sends an envelope is still proxied as a plain HTTP POST, but nothing
SOAP-specific is offered on that side.
The examples on this page use the sample order service of the built-in demo backend
(POST /soap/orders on port 9100, WSDL at /soap/orders?wsdl): orders A-1001 and A-1002
exist, any other id is a fault.
What the caller sees¶
An API orders with an operation POST /orders/get. The caller sends JSON:
and receives JSON:
{
"OrderId": "A-1001",
"Status": "shipped",
"Customer": {"Name": "Ada Lovelace", "Email": "ada@example.com"},
"Lines": {"Line": [{"Sku": "X1", "Qty": "2"}, {"Sku": "X2", "Qty": "1", "Note": "leave at the door"}]}
}
The names are the backend's element names, as its documentation writes them; the gateway does not rename them. An unknown order answers with the gateway's problem+json and a stable code:
HTTP/1.1 400 Bad Request
Content-Type: application/problem+json
X-Apinx-Error: APX-SOAP-0002
{"code": "APX-SOAP-0002", "title": "The backend rejected the request", …}
To give callers the shape you want (camelCase keys, numbers as numbers), add response.jq to
the policy or a transform to the operation; both are shown below.
Adding an operation by hand¶
One soap policy per operation, bound on the operation. The template is the operation element
of the envelope, written in XML with references to the JSON body; the gateway adds the
Envelope, Header and Body around it.
apiVersion: apinx/v1
kind: API
name: orders
base_path: /orders
upstream: orders-soap # targets: http://orders.internal:8080
strip_prefix: true
policies:
- type: api-key
- type: rate-limit
config: { limit: 100, window: 1m }
operations:
- name: get
path: /get
methods: [POST]
policies:
- type: soap
config:
version: "1.1"
action: urn:example:orders/GetOrder
endpoint_path: /soap/orders # the service's one path, whatever the operation's own
namespaces:
ord: urn:example:orders
request: |
<ord:GetOrder>
<ord:OrderId>${body.orderId}</ord:OrderId>
</ord:GetOrder>
response:
unwrap: GetOrderResponse/Order
arrays: [Line]
- name: create
path: /create
methods: [POST]
policies:
- type: soap
config:
action: urn:example:orders/CreateOrder
endpoint_path: /soap/orders
namespaces:
ord: urn:example:orders
request: |
<ord:CreateOrder>
<ord:Customer>
<ord:Name>${body.customer.name}</ord:Name>
<ord:Email>${body.customer.email}</ord:Email>
</ord:Customer>
<ord:Lines>
${each body.lines as line}
<ord:Line>
<ord:Sku>${line.sku}</ord:Sku>
<ord:Qty>${line.qty}</ord:Qty>
${if line.note}<ord:Note>${line.note}</ord:Note>${end}
</ord:Line>
${end}
</ord:Lines>
</ord:CreateOrder>
response:
arrays: [Line]
A SOAP service has one address for all its operations, so endpoint_path names the path the
envelope is posted to; without it the backend receives the operation's own path (after
strip_prefix), which is right only when the upstream's target already carries the whole
address. The policy is bound on an operation only: on an API, a shared flow, an environment
or the gateway it is refused at validation (soap is bound on an operation (route) only: it
describes one operation's request and answer; bind it on each operation).
The request template¶
The template uses the references transformations know, plus two blocks of its own:
| In the template | Inserts |
|---|---|
${body.orderId}, ${body.customer.name} |
A field of the JSON body, dotted for nested fields |
${path.id}, ${query.page}, ${header.X-Tenant} |
A path parameter, a query parameter, a request header |
${claim.sub}, ${principal.id}, ${principal.name} |
The caller's validated JWT claim, or the authenticated application |
${client_ip}, ${host}, ${method}, ${route} |
The connection and the match |
${callout.<name>.body.<field>} |
The answer of a service callout that ran before the backend |
${each body.lines as line} … ${end} |
The content once per element of the JSON array lines; inside it ${line.sku} is the element's field |
${if body.note} … ${end} |
The content only when note is present and not empty |
Every inserted value is XML-escaped: &, <, >, " and ' become entities, so a caller
who sends "orderId": "</ord:OrderId><ord:Admin>true</ord:Admin>" puts that text inside
OrderId and nothing else. A string is inserted as it is, a number or a boolean in its JSON
form (2, 2.5, true), and a missing field, null, an object or an array insert nothing;
there is no default syntax, so an element that must carry a value when the caller sends none
is written by hand. A body may be empty when the operation takes nothing; a body that is not a
JSON object (an array, a bare value, text) is refused with 400 APX-SOAP-0001 before the
backend is called.
The two blocks:
${each <array> as <var>}repeats its content once per element. The array is a field of the body or of an enclosing loop variable, soeachnests one level: lines inside an order, options inside a line; a third level is refused at save. An empty or missing array emits nothing. The loop variable is lowercase letters and underscores and may not be a reference kind (body,path, …) or a block word.${if <ref>}emits its content when the value is present and not empty: absent,null,"",[]and{}emit nothing;falseand0count as present. Any reference kind works, so${if header.X-Tenant}is fine.
Each block must be complete XML on its own (an element opened inside a block closes inside it),
so ${if line.note}<ord:Note>${line.note}</ord:Note>${end} is the shape, and
${if x}<a>${end}</a> is refused. The template starts with the operation element, the one
whose name the backend dispatches on; a comment or text before it is refused.
Templates are compiled when the operation is saved or the file is loaded. One that is not
well-formed XML once its references are filled, that uses a reference kind the gateway does not
know, or that opens a block it does not close, is refused with the line named
(APX-SOAP-0006: line 4: element ${bdy.id}) is caught then, not at the first request.
What the backend receives¶
For the get operation above and {"orderId": "A-1001"}:
POST /soap/orders HTTP/1.1
Content-Type: text/xml; charset=utf-8
SOAPAction: "urn:example:orders/GetOrder"
Accept: text/xml
Accept-Encoding: identity
<?xml version="1.0" encoding="UTF-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ord="urn:example:orders"><soap:Body><ord:GetOrder>
<ord:OrderId>A-1001</ord:OrderId>
</ord:GetOrder></soap:Body></soap:Envelope>
With version: "1.2" the envelope namespace is http://www.w3.org/2003/05/soap-envelope
(prefix env), the request is Content-Type: application/soap+xml; charset=utf-8;
action="urn:example:orders/GetOrder" and no SOAPAction header is sent. With 1.1 an empty
action sends SOAPAction: "", which many stacks require. The caller's Content-Type is never
forwarded; the Header element appears when headers or security fills it. The envelope is
kept for the upstream's retries, and an envelope larger than max_body is refused with 413
APX-SOAP-0005 without a call.
Settings¶
| Setting | Default | Meaning |
|---|---|---|
version |
1.1 |
1.1: text/xml with a SOAPAction header. 1.2: application/soap+xml with the action parameter. |
action |
The SOAPAction (1.1) or action parameter (1.2); a URI without quotes or spaces. | |
namespaces |
Prefix → namespace URI, declared on the Envelope so the template can use the prefixes. The envelope's own prefix (soap or env), wsse and wsu with username_token, and prefixes starting with xml are reserved. |
|
request |
required | The operation element with references inside. |
headers |
Extra SOAP header elements, references allowed: WS-Addressing by hand, a custom header the service expects. | |
security |
none |
username_token adds a wsse:Security header built from the four fields below. |
username |
The token's username; references allowed (${claim.tenant}). Required with username_token. |
|
password |
The token's password, a secret: stored encrypted, accepted as a value or an env:, file: or vault: reference, masked in the console, redacted in exports. Required with username_token. |
|
password_type |
text |
text sends PasswordText; digest sends PasswordDigest with a Nonce and Created, so the password never travels. |
timestamp |
false |
Adds wsu:Created to a PasswordText token (a digest token always carries it). |
response.unwrap |
The element path under the Body whose content becomes the JSON, segments separated by / (GetOrderResponse/Order). Empty: the first child of the Body, the …Response element. |
|
response.arrays |
Element names that are always arrays, even when one is present (Line, Order). |
|
response.attributes |
drop |
keep turns attributes into @name keys. |
response.types |
string |
infer types numbers and booleans; string keeps every text value a string. |
response.jq |
A jq program run on the converted JSON; its single output is the body. Same compiler and time budget as transform. |
|
response.limits.depth |
32 | Deepest element nesting accepted in the answer. |
response.limits.elements |
100,000 | Most elements accepted in one answer. |
response.limits.text |
1 MB | Longest text of one element; up to 1 GB. |
max_body |
1 MB | Largest caller body and largest envelope built from it; over it 413 APX-SOAP-0005. |
max_response |
4 MB | Largest backend answer; over it 502 APX-SOAP-0004. |
endpoint_path |
The path on the backend the envelope is posted to, replacing the request's own; an absolute path without a query. The import sets it from the WSDL. |
The policy reference is generated from the same descriptor.
Where it runs in the chain¶
The policy sits in the transformation phase. On the request it runs after transform and
the before-phase callouts of service-callout, so a request-body program or a callout can
prepare the JSON the template reads (${callout.tenant.body.region} is a valid reference). On
the response its hook runs before transform and service-callout, so a response-body
program sees the decoded JSON, not XML, and after-phase callouts can read ${response.body.…}
from it. cache, normalize-errors and the rest of the chain see a JSON operation.
How the answer becomes JSON¶
The rules are fixed and the same for every service:
| Rule | Example | |
|---|---|---|
| 1 | Namespaces are dropped from element names; case is kept as written. | <ord:Status> → "Status" |
| 2 | An element with only text becomes a string, or a typed value with types: infer. |
<Qty>2</Qty> → "2", or 2 |
| 3 | An element with children becomes an object. Repeated siblings become an array; names in response.arrays are arrays even when one is present. |
<Lines><Line>…</Line><Line>…</Line></Lines> → {"Line": [{…}, {…}]} |
| 4 | xsi:nil="true" becomes null; an empty element becomes "". |
<Note xsi:nil="true"/> → null |
| 5 | Attributes are dropped unless attributes: keep, then they are @name keys; a text element with kept attributes becomes an object with its text under #text. |
<Qty unit="pcs">2</Qty> → {"@unit": "pcs", "#text": "2"} |
| 6 | The result is the content of unwrap; the envelope, the header and the wrapper are never returned. Text mixed between children has no JSON shape and is dropped. |
types: infer types true and false, and text that is a JSON number: 2, -3.5, 1e3.
Anything else stays a string, including 007, 0x10 and an integer too large for 64 bits, so
an identifier that happens to look like a number is never rewritten. Element names are JSON
keys as they are; to rename or reshape, response.jq runs on the converted value:
response:
unwrap: GetOrderResponse/Order
arrays: [Line]
types: infer
jq: |
{id: .OrderId, status: .Status,
customer: {name: .Customer.Name, email: .Customer.Email},
lines: [.Lines.Line[] | {sku: .Sku, qty: .Qty, note: .Note}]}
gives {"id": "A-1001", "status": "shipped", "customer": {…}, "lines": [{"sku": "X1", "qty":
2, "note": null}, …]}. A transform with a response.body.program on the same operation does
the same job one step later and also sees the JSON.
Before decoding, the answer runs through the XML threat inspector with the policy's
response.limits: a DTD or an entity declaration is always refused, whatever a
threat-protection policy on the operation allows (that policy guards the caller's side, not the
backend's), and depth, element count and text length are bounded. The converted body is served
as application/json; charset=utf-8 with its own Content-Length; of the backend's headers
only Date, Cache-Control, Expires and Age are kept.
Faults and errors¶
| Code | Status | When |
|---|---|---|
APX-SOAP-0001 |
400 | The caller's body is not a JSON object: an array, a bare value, text, or invalid JSON. The backend is not called. |
APX-SOAP-0002 |
400 | The backend answered a fault with code Client (1.1) or Sender (1.2): what was sent did not satisfy it. |
APX-SOAP-0003 |
502 | The backend answered a fault with code Server, Receiver or any other code: a failure on its side. |
APX-SOAP-0004 |
502 | The answer cannot be converted: not XML, not an envelope, no Body, nothing at the unwrap path, larger than max_response, outside the XML limits, or a DTD. |
APX-SOAP-0005 |
413 | The caller's body, or the envelope built from it, is larger than max_body. The backend is not called. |
APX-SOAP-0006 |
400 at save | The request or headers template does not compile; the message names the line. Never seen by a caller. |
A fault is recognised by its envelope, whatever HTTP status the backend used (SOAP 1.1 stacks
send 500). The gateway's error carries the fault's faultcode (and the 1.2 subcode),
faultstring or Reason, and the text of detail, plus the backend's status. With verbose
errors on (console.errors.verbose: true, or a UAT environment) the caller sees them in the
error's details; in production the caller sees the code and the message, and the details are in
the request inspector and the log. Analytics counts a fault as the status it was mapped to, so
a service that answers Client faults for bad ids shows them as 400s, not as backend errors.
Every code is in the error reference with its remediation.
WS-Security UsernameToken¶
A backend that wants a wsse:UsernameToken in the envelope gets it from the policy; HTTP-level
credentials (Basic, bearer, OAuth 2 client credentials) stay with upstream-auth,
and the two combine when a service wants both.
- type: soap
config:
action: urn:example:orders/GetOrder
endpoint_path: /soap/orders
namespaces: { ord: urn:example:orders }
request: |
<ord:GetOrder><ord:OrderId>${body.orderId}</ord:OrderId></ord:GetOrder>
response: { unwrap: GetOrderResponse/Order, arrays: [Line] }
security: username_token
username: svc-gateway
password: env:ORDERS_SOAP_PASSWORD
password_type: digest
passwordis a secret field, handled exactly asupstream-auth's: stored encrypted (ADR-0014), accepted as a value or as anenv:,file:orvault:reference resolved when the configuration is published, masked in the console and redacted in every export. It is never written to a log, a trace or an error. The template text itself never holds it.password_type: textsends the password as PasswordText.digestsendsBase64(SHA-1(nonce + created + password))with a 16-byte randomNonceandwsu:Createdbeside it, as the WSS UsernameToken profile 1.1 defines, so the password never travels.timestamp: trueaddswsu:Createdto a text token for stacks that require it.usernamemay use references (${claim.tenant}), the password may not.- Saving with
username_tokenand no username or no password is refused.
The header the backend receives:
<soap:Header>
<wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"
xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<wsse:UsernameToken>
<wsse:Username>svc-gateway</wsse:Username>
<wsse:Password Type="…#PasswordDigest">kB6fS…</wsse:Password>
<wsse:Nonce EncodingType="…#Base64Binary">dGhpcyBpcyBhIG5vbmNl</wsse:Nonce>
<wsu:Created>2026-10-27T08:15:00Z</wsu:Created>
</wsse:UsernameToken>
</wsse:Security>
</soap:Header>
The demo order service checks the token when the request carries X-Demo-Require-Token: 1
(username svc-gateway, password orders-secret, text or digest), so a set-header policy
with that header on the operation lets you try a wrong and a right password without a real
backend.
Importing a WSDL¶
The import reads a WSDL 1.1 description and proposes the API, its backend, one operation per
SOAP operation and the soap policy of each, with a JSON example per operation. You review and
edit everything before anything is created, as with the Postman import.
- Get the WSDL as a file or text: most stacks serve it at the service address with
?wsdl(curl -s https://orders.example.com/soap/orders?wsdl -o orders.wsdl). Descriptions up to 3 MB are imported. - Admin → Import & export → Import an API → WSDL: choose the file or paste it.
- The preview shows the API, the backend, the operations with their paths and the policies suggested, plus notes (what the import adapted) and issues (what it could not import, each with the reason). Edit the API's name and base path, rename paths, untick operations, change the backend address. Each operation shows its request template, the path of the answer and a JSON example.
- Create API and N operations. All or nothing: everything is created in the draft, or nothing is and every problem is listed. Deploy to serve it.
What becomes what¶
| In the WSDL | In Apinx |
|---|---|
service/@name (OrderService) |
The API's name, kebab-cased: order-service; its documentation is the description |
| The first SOAP 1.1 port of the first service (else the first SOAP 1.2 port) | The version of every operation; the other ports and services are listed in the notes |
soap:address/@location (http://orders.internal:8080/soap/orders) |
A new upstream order-service-soap with http://orders.internal:8080 (or the existing upstream that already reaches it); the path becomes every operation's endpoint_path. Nothing is fetched, and credentials written into the address are dropped |
Each operation of the binding |
One operation POST /<operation-name-kebab> (/get-order); its documentation is the summary |
soap:operation/@soapAction |
action |
| The input element and the types behind it | The request template: one element per field, ${body.<Name>} per text element, ${each} around maxOccurs="unbounded", ${if} around minOccurs="0"; the namespaces the template uses |
| The output element | response.unwrap (GetOrderResponse/Order when the wrapper holds one element with children) and response.arrays (the unbounded names) |
rpc style with use="literal" |
A template whose operation element wraps the parts, in the binding's namespace |
Simple types, sequence, all, complexType, extension (one level), nillable |
Elements of the template; the JSON example has "string", 0, false, a date, one element per array |
choice |
A comment listing the alternatives, each in an ${if} block, so a request sends one |
JSON keys are the WSDL's element names (OrderId, not orderId): the example and the template
agree key for key, and renaming a key in the template renames what callers send. The suggested
policies are request-size-limit (1 MB) and allow-methods (POST), both ticked.
What is not imported¶
The preview lists each, with the reason; none stops the API being created unless no operation is left.
- External
wsdl:import,xsd:importandxsd:include: nothing is fetched, ever. The location is listed; an operation whose types are in the missing document gets a comment in its template where they go, to complete by hand. Paste a self-contained WSDL when you can. - rpc/encoded operations (SOAP encoding): skipped, with an error. Most stacks can also serve an operation as document/literal.
- MIME attachments (multipart): skipped.
- SOAP headers declared in the binding: listed; write them in the policy's
headers. - WS-Policy (
wsp:Policy) assertions: not read; security and addressing are set on each operation by hand. anyType,xsd:any, element and attribute groups: a comment where the content goes.- Attributes of a request element: not written; the issue names them.
- Recursive types: the template stops at the first level.
- Fault messages: not needed; every fault is mapped by the rules above.
- Operations without an input message, bound operations that the port type does not declare, and port-type operations the binding does not bind.
Files that are refused¶
| The file | Code | What to do |
|---|---|---|
| Not XML, no SOAP binding, or no operation that can be imported | APX-GW-0013 |
Save the description as served at ?wsdl, whole |
| WSDL 2.0, an XML Schema on its own, JSON | APX-GW-0014 |
Convert a WSDL 2.0 description; import a schema through the WSDL that uses it; an OpenAPI document and a Postman collection have their own imports |
| Over 3 MB | APX-GW-0015 |
Remove embedded documentation and WS-Policy blocks, or split the services into one WSDL each |
Re-importing a WSDL into an existing API is not offered: import it as a new API, or edit the operations by hand.
From the Admin API¶
As for Postman: POST /api/v1/import/wsdl/preview with {"document": "<wsdl…>"} returns the
proposal; POST /api/v1/import/wsdl creates it, as edited ({"proposal": …}) or as previewed
({"document": …}).
jq -n --rawfile doc orders.wsdl '{document: $doc}' |
curl -s -X POST localhost:9000/api/v1/import/wsdl/preview \
-H "Authorization: Bearer $TOKEN" -H 'Content-Type: application/json' -d @-
In the console¶
An operation that carries a soap policy shows it in the generated form: request and
headers are XML editors, password is masked. Fields beside the template lists the
references it reads and the JSON example the import produced. Try it starts from a JSON body
derived from the template (${body.a.b} gives {"a": {"b": ""}}, an ${each} an array with
one element), so a hand-written template gets a starting point too, and shows the JSON answer;
Backend exchange shows the envelope sent and received while tracing is on. The
assistant has the walkthrough Expose a SOAP service as a JSON API and knows
the policy's fields.
The trace and the inspector¶
The soap step of a traced request records the operation, the JSON and envelope sizes and the
conversion time, and names the fault when there is one. Under the trace's body rules the step
also keeps the backend exchange: on premises both envelopes, up to the body-preview length,
with wsse:Password and any element whose name matches the sensitive-field list blanked
(Observability); the access log and analytics see a JSON operation with the
mapped status.
Apinx Cloud¶
- No new plan rule: the plan's largest response (10 MB on Free) bounds the backend's answer
before
max_responsedoes, and the backend address passes the same egress guard and port rules as any upstream. - A trace keeps the sent envelope only, while a trace window with request bodies is on (the first 1,000 characters, password blanked), and never the received one, as for every response body in Apinx Cloud (what a Cloud trace shows).
- The WSDL import never fetches anything, so a description that points at a private address imports; the deploy refuses the backend if the address is one the plan cannot reach.
Limits¶
- Caller body and envelope:
max_body, 1 MB by default. - Backend answer:
max_response, 4 MB by default; XML depth 32, 100,000 elements, 1 MB of text per element, 64 attributes and names of 256 characters per element; DTDs and entity declarations always refused. response.jqruns within the transform time budget (50 ms).eachnests one level; a template is checked for well-formedness at save.- No new timeout: the upstream's
timeouts.totalbounds the exchange. - WSDL import: 3 MB per description; one service and one port per import.
Not supported¶
- SOAP as a caller-facing interface: the gateway serves no WSDL and validates no incoming envelope. A caller that sends XML is proxied as plain HTTP.
- WSDL 2.0, rpc/encoded (SOAP-encoding arrays), MTOM and attachments, WS-Addressing beyond what
you write in
headers, WS-Security signing and encryption, WS-ReliableMessaging, SOAP over anything but HTTP(S). - Fetching external schemas or WSDLs during import.
- Generating a WSDL, or an OpenAPI document of the JSON side beyond the usual export.
- A default value in a reference (
${body.x|none}), andeachmore than two levels deep.
Cost¶
A route without the policy pays nothing: the policy is simply not in its chain, and the
allocation gate holds the plain-route benchmarks. On a SOAP operation the template is compiled
once per publish and rendered as appends to a pooled buffer (the GetOrder template renders
without an allocation); the answer is decoded once, bounded by max_response; the numbers are
in ADR-0037.