SOAP web services
Most new APIs are REST (recipe 5.2), but plenty of older systems still speak SOAP: ticket tools, IP address managers, storage arrays, and vCenter itself, whose vSphere API is a SOAP API underneath. Orchestrator’s SOAP plug-in reads a service’s WSDL, the XML file that describes its operations, and turns every operation into an object you can call.
This recipe uses vCenter’s SOAP API as the example, because every VCF lab has one and one of its operations needs no login.
Getting ready
- A vCenter, here
vc01.vmw.lab, whose certificate Orchestrator already trusts (recipe 1.9). The SOAP plug-in uses the same trust store. - The module
com.vcfguide.chapter5.
How to do it
Add the SOAP host
-
In Library > Workflows, run Add a SOAP host (folder Library > SOAP > Configuration) with:
Field Value Name vc01-soapProvide WSDL content No WSDL URI https://vc01.vmw.lab/sdk/vimService.wsdlConnection timeout (in seconds) 30Request timeout (in seconds) 60Authentication type None On the Host authentication page, leave Authentication type at None. Orchestrator downloads the WSDL and the files it imports, and builds an operation for each SOAP call; for the vSphere API the run took about ten seconds.
-
A WSDL says where its service lives, and vCenter’s says
https://localhost/sdk, which from Orchestrator is the wrong machine. Run Update a SOAP host with an endpoint URL onvc01-soapwithhttps://vc01.vmw.lab/sdk. From now on, calls go there instead of to the address in the WSDL.
Inventory > SOAP > vc01-soap expanded, with the operation RetrieveServiceContent selected and its input parameters _this and _this(type) shown.
Call an operation from a script
- Each operation lists its inputs and outputs as flat names: nested elements are joined with dots, and an XML attribute appears with its name in brackets.
RetrieveServiceContenthas the inputs_thisand_this(type), and outputs such asreturnval.about.fullName. Create the actiongetSoapServiceInfoincom.vcfguide.chapter5, with the inputhost(SOAP:Host) and the return typeProperties:
if (!host) { throw "[VCFG][getSoapServiceInfo] host is required";}var operation = host.getOperation("RetrieveServiceContent");if (!operation) { throw "[VCFG][getSoapServiceInfo] " + host.name + " has no operation RetrieveServiceContent";}// The operation's inputs, as listed by operation.getInParameters(): _this and _this(type)var request = operation.createSOAPRequest();request.setInParameter("_this", "ServiceInstance");request.addInParameterAttribute("_this", "type", "ServiceInstance");
var response = operation.invoke(request);var info = new Properties();info.put("fullName", response.getOutParameter("returnval.about.fullName"));info.put("version", response.getOutParameter("returnval.about.version"));info.put("build", response.getOutParameter("returnval.about.build"));info.put("apiVersion", response.getOutParameter("returnval.about.apiVersion"));System.log("[VCFG][getSoapServiceInfo] " + host.name + ": " + info.get("fullName"));return info;- Run it with
vc01-soap. It returns the vCenter’s product name, version, build and API version, such asVMware vCenter Server 9.1.1.0.25712839.
Without code
- The folder Library > SOAP has two workflows for calls without code. Invoke a SOAP operation takes an operation and up to 15 parameters and 5 headers as text, in the order the operation lists them, and returns the response’s parameters and headers as
Properties. Generate a new workflow from a SOAP operation writes a workflow for one operation, which you can then edit like any other.
isWsdlLocal: true means “use the WSDL text I paste”, not “download it”, despite its description. The certificate of a vCenter already added to the vSphere plug-in was accepted without a prompt.How it works
The WSDL is the contract. It lists every operation, the XML each one takes and returns, and the service’s address. The SOAP plug-in parses it once, when you add the host, and stores the result, so your scripts work with names rather than raw XML. If the service changes its WSDL, run Update a SOAP host to read it again.
Flat names for nested XML. SOAP messages are trees. The plug-in flattens them: returnval.about.version is the version element inside about inside returnval, and _this(type) is the type attribute of _this. getInParameters() and getOutParameters() on an operation list the names it expects, so print them first when you write a call to a new service.
When to use the vSphere plug-in instead. This recipe calls vCenter through SOAP only because it’s a SOAP service everyone has. For real vCenter work, use the vSphere plug-in (recipe 8.1): it logs in for you, keeps a session, and gives you typed objects instead of strings. Use the SOAP plug-in for systems that have no plug-in of their own.
Logging in. Most services need credentials. Add a SOAP host offers Basic, Digest and Negotiate (Kerberos, with the service’s SPN), with a Shared Session (one account for everyone) or a Per User Session (the credentials of whoever runs the workflow), as the REST plug-in does (recipe 5.2). Some services want a login operation first and a token in a header on every later call; set it with request.setInHeader() or request.setHttpHeader().
See also
- 5.2 REST hosts and operations, the plug-in to prefer when a system has a REST API.
- 5.6 XML and JSON, for working with raw XML when you need to.
- 8.1 Workflows against vCenter, the right way to automate vCenter.
