Development · LessonBy Praveen T, ServiceNow Trainer, 9 yrs · Published · ServiceNow · all levels
SOAP messages
Call SOAP services from the platform: WSDL import, envelopes, authentication and error handling.
Quick answer
Call SOAP services from the platform: WSDL import, envelopes, authentication and error handling.
Key takeaways
- Generate from WSDL where possible
- Parse responses with XMLDocument2, not regex
- Route internal endpoints through a MID server
- SOAP faults carry useful detail, log them
Creating the message
A SOAP message can be generated from a WSDL, which creates functions for each operation with the envelope prefilled. Variables in the envelope use the ${var} syntax and are supplied at runtime.
Calling it
SOAPMessageV2 mirrors the REST API in shape.
var s = new sn_ws.SOAPMessageV2('AcmeBilling', 'getInvoice');
s.setStringParameterNoEscape('invoiceId', id);
s.setHttpTimeout(20000);
var resp = s.execute();
if (resp.getStatusCode() != 200) {
gs.error('Billing SOAP failed: ' + resp.getErrorMessage());
}
var xml = new XMLDocument2();
xml.parseXML(resp.getBody());Practical notes
SOAP endpoints are usually internal and strict.
- Route through a MID server for internal services
- Namespaces matter, parse with XMLDocument2 rather than string matching
- WS-Security headers are often required, add them in the envelope
- Log the fault string, SOAP faults return detail that plain status codes do not
Practice challenge
+0 XPStreak ×0
Question 1 of 2
Which class parses a SOAP response body?
Frequently asked questions
Should new integrations use SOAP?
Only when the provider offers nothing else. REST is simpler to operate and debug.
How do we handle WS-Security?
Add the security header to the envelope and store credentials in a credential record referenced by the message.