operation.prepare { ... } is the single structured request interface.
operation.prepare do
tag('CreateOrder') do
tag('customerId', 'C-123')
tag('amount', '42.50')
end
endReserved DSL methods:
tagheaderbodyws_securitytextcdatacommentpixmlnsattribute
If an element name matches a reserved method name, use tag('name').
Each operation inherits its endpoint, SOAP version, SOAP action, and encoding from the WSDL. These can be overridden per-operation:
# Redirect to a different endpoint (e.g., test environment)
operation.endpoint = 'https://staging.example.com/api'
# Switch SOAP version ('1.1' or '1.2')
operation.soap_version = '1.1'
# Override the SOAP action, or set to nil to clear
operation.soap_action = 'urn:example#CustomAction'
# Change XML encoding (defaults to UTF-8)
operation.encoding = 'ISO-8859-1'All setters validate their input and raise ArgumentError on invalid values. Overrides are not cleared by operation.reset! — they persist across request cycles.
Auto-generated HTTP headers (Content-Type, SOAPAction) are derived from the operation's SOAP version, action, and encoding. Use http_headers= to merge custom headers on top — user values win on conflict, while auto-generated defaults are preserved:
# Add a custom header alongside auto-generated ones
operation.http_headers = { 'X-Auth-Token' => 'bearer-abc123' }
operation.http_headers
# => { "Content-Type" => "text/xml;charset=UTF-8",
# "SOAPAction" => "\"urn:example#GetOrder\"",
# "X-Auth-Token" => "bearer-abc123" }
# Override an auto-generated header
operation.http_headers = { 'Content-Type' => 'application/xml' }Custom headers are cleared by operation.reset!.
Top-level content defaults to SOAP body.
operation.prepare do
header do
tag('AuthToken', 'secret')
end
tag('GetOrder') do
tag('orderId', 123)
end
endbody do ... end is optional and equivalent for top-level body content.
operation.prepare do
xmlns('ord', 'http://example.com/orders')
tag('ord:CreateOrder') do
attribute('priority', 'high')
tag('customerId', 'C-123')
end
endRules:
- Element and attribute names are validated as XML NCName/QName.
- Prefixed names require a declared namespace.
- Reserved prefixes cannot be overridden:
wsse,wsu,ds,ec,env,soap,soap12,xsi.
operation.prepare do
tag('Submit') do
text('normal text <escaped>')
cdata('<raw xml="kept as-is"/>')
comment('diagnostic marker')
pi('xml-stylesheet', 'type="text/xsl" href="style.xsl"')
end
end- Text and attribute values are XML-escaped automatically.
- CDATA preserves verbatim content.
Use operation.contract to generate a starting request:
template = operation.contract.request.body.template(mode: :minimal)
puts template.to_dslModes:
:minimal: required elements/attributes only.:full: includes optional content and wildcard hints.
Use operation.prepared? to check whether prepare has been called:
operation.prepared? # => false
operation.prepare do
tag('GetOrder') { tag('orderId', 123) }
end
operation.prepared? # => true
operation.reset!
operation.prepared? # => falseValidation runs immediately when the prepare block finishes. See Strictness for full details.
strictness.request_validation enabled (default):
- Enforces operation-relevant schema completeness.
- Rejects unknown elements/attributes unless wildcard-permitted.
- Enforces required elements, order, and cardinality where known.
strictness.request_validation disabled:
- Tolerates recoverable import failures.
- Validates known structure where available.
- Allows unknown structure when schema metadata is missing.
Request envelope construction enforces resource limits:
max_request_elementsmax_request_depthmax_request_attributes
Configure via limits::
definition = WSDL.parse(url)
client = WSDL::Client.new(
definition,
limits: {
max_request_elements: 50_000,
max_request_depth: 200,
max_request_attributes: 5_000
}
)Request XML is compact by default (no extra whitespace). For debugging, use pretty: true:
puts operation.to_xml(pretty: true)For rpc/literal, request serialization applies an operation wrapper when needed, using soap:body@namespace if present.