You can call a SOAP service from a ViewModel action by using the selfVM.SoapCall OCL operator; this page is for MDriven Designer users who need to construct the SOAP request from ViewModel data.
Call a SOAP operation
SoapCall is available on selfVM, the ViewModel reference used in OCL and EAL expressions. It sends a SOAP request to the service and returns the response body as a string.
selfVM.SoapCall(targeturl, action, actionnamespace, user, pwd, nestingWithParams, passwordDigest, SOAPAction)
| Argument | Purpose |
|---|---|
targeturl
|
URL of the SOAP service endpoint. Use the service URL, not the URL of one operation. |
action
|
Name of the SOAP operation. MDriven also places this action in the generated request body. |
actionnamespace
|
Namespace for the operation. MDriven declares this namespace as nsAction and uses that prefix for the operation and for parameters that do not specify another namespace. Copy the namespace exactly from the service definition, including case and any trailing slash.
|
user and pwd
|
Credentials for services that require a username and password. Pass empty strings for an open service. |
nestingWithParams
|
Name of the ViewModel nesting that contains the operation parameters. The nesting and its columns define the XML below the operation element. |
passwordDigest
|
Controls whether the password is sent as clear text or by using nonce, creation time, and hash handling. Use the value required by the SOAP service. |
SOAPAction
|
Value for the HTTP SOAPAction header. The action is used as the SOAPAction header value when no separate value is supplied.
|
The six-argument form is suitable when you do not need the final two options:
vNewVar := selfVM.SoapCall(
'http://www.webserviceX.NET/stockquote.asmx',
'GetQuote',
'http://www.webserviceX.NET/',
'',
'',
'NestingWParams')
This expression assigns the returned SOAP body to the ViewModel variable vNewVar.
Build the parameter nesting
The nestingWithParams argument names a ViewModel nesting (the blue box in MDriven Designer). Each column in that nesting becomes an XML parameter element. The column's runtime name becomes the element name, and its OCL expression supplies the value.
To call an operation that accepts one symbol parameter:
- Create a ViewModel nesting named
NestingWParams. - Add a column with runtime name
symbol. - Set its expression to a value, for example
'IBM', a model attribute, or a ViewModel variable. - Add an action and assign the result of
selfVM.SoapCall(..., 'NestingWParams')to a ViewModel variable. - Execute the action and inspect the result variable.
With the example call, MDriven generates the operation and parameter structure equivalent to:
<soap:Body xmlns:nsAction="http://www.webserviceX.NET/">
<nsAction:GetQuote>
<nsAction:symbol>IBM</nsAction:symbol>
</nsAction:GetQuote>
</soap:Body>
Represent nested input types
A SOAP operation can require a complex parameter with child elements. Model this by adding a nesting to the parameter nesting. The containing column becomes the outer XML element; its detail association supplies the child elements.
For example, if a service expects BarCodeParam with several values beneath the operation, create a parameter column named BarCodeParam and place the required child columns in its detail nesting. MDriven writes the outer element and then the nested parameters.
The order of columns and nestings is significant. Arrange them in the same order required by the SOAP service definition. An incorrect order can produce a request that the service rejects even when all values are present.
Control XML namespaces
By default, MDriven writes parameter elements with the nsAction prefix from actionnamespace. You can override this per parameter by defining namespace columns on the root ViewModel.
A namespace column must:
- Be a root ViewModel column.
- Have a runtime name beginning with
ns. - Return a String value containing the namespace URI.
For example, define a root column with runtime name nsAdditionalNameSpace and an expression that returns 'AdditionalNameSpaceAdded'. In the parameter nesting, name a column nsAdditionalNameSpace_SomeString. MDriven removes the prefix before the underscore from the element name, uses that prefix for the element, and adds its namespace declaration.
<nsAdditionalNameSpace:SomeString xmlns:nsAdditionalNameSpace="AdditionalNameSpaceAdded">Hello</nsAdditionalNameSpace:SomeString>
To generate an element with no namespace, start its column runtime name with an underscore. For example, _SomeString produces <SomeString>...</SomeString> rather than an nsAction:SomeString element.
| Parameter-column runtime name | Generated element pattern |
|---|---|
SomeString
|
<nsAction:SomeString>...</nsAction:SomeString>
|
_SomeString
|
<SomeString>...</SomeString>
|
nsAdditionalNameSpace_SomeString
|
<nsAdditionalNameSpace:SomeString xmlns:nsAdditionalNameSpace="...">...</nsAdditionalNameSpace:SomeString>
|
Authentication and client certificates
When you provide user and pwd, MDriven adds SOAP security information to the request header. Use passwordDigest when the service specifies password-digest rather than clear-text password handling.
For a client-certificate call, add a root ViewModel column named ClientCertThumbPrint. MDriven looks up the certificate by this thumbprint and uses it for the call.
Inspect the request and response
Add these String ViewModel variables when you need to diagnose a call:
| Variable | What MDriven writes |
|---|---|
vSoapDebug
|
The complete SOAP envelope immediately before it is sent. Use it to compare the generated XML, namespaces, and parameter order with the service requirement. |
vSoapResult
|
The value returned by the service. MDriven attempts to convert it to XML. |
vSoapError
|
An exception encountered while parsing the response. |
Use vSoapDebug first when a service rejects a request. Check the endpoint, action namespace, parameter nesting name, element order, and namespace prefixes. A successful SOAP response can still contain encoded XML inside a result element; in that case, clean the returned content before mapping it to objects.
