Matching SOAP requests and sending SOAP responses
SOAPAction
header and the request body XML.
SOAPAction
header to select the appropriate action for the call.
Although you can sometimes avoid this, it’s usually a good idea to add a header match for SOAPAction
as it’s more
efficient and faster than relying exclusively on the XML body.
equalToXml
is a straightforward way to specify a match.
For instance given a SOAP service for managing a to do list, you may wish to mock an interaction matching a specific request to add an item:
TransactionId
element, which
must be a unique value for each request e.g.:
equalToXml
can become quite slow as it must perform a comparison on every node in the XML document.
It’s often faster to match specific elements within the document using the matchesXPath
operator,
and since this is a much looser approach to matching it’s another way to solve
the problem described above where frequently changing values are present.
When matching using XPath, your aim should be to target as few elements/attributes as possible while being able
to reliably distinguish between requests.
Given the same request body as in the previous section, we could use the following
XPath to match just on the value of the m:ToDoItem
element:
UserId
field that we also wanted to target:
matchesXPath
body pattern for each of the elements we
care about: