Skip to content

$Services

Provides dynamically generated proxies for SOAP services configured on the process. Each configured service, endpoint, and operation becomes a property under this object at runtime.

1
const $Services: object;

Remarks

Parameter names and result shapes are defined by the selected service operation's WSDL, so they cannot be expressed statically in this declaration. Service proxy creation lazily compiles the discovery XML schema and resolves configured credentials on first use. Use the generated autocomplete members for the configured service.

An operation is called as $Services.<service>.<endpoint>.<operation>(body, headers, options):

  • body: the request body, as an object or an XML string.
  • headers: values for SOAP headers defined by the service, matched by name. Optional.
  • options: call options. Optional.
  • url: overrides the endpoint URL defined in the WSDL.
  • timeout: the maximum time to wait for the reply, in seconds.
  • return: 'request' returns the generated request message without calling the service; 'response' returns the whole response message.

The call waits for the reply and returns the first element of the response body as an Xml node. SOAP faults and connection errors are thrown as script errors.

Examples

Call a SOAP operation with an object

1
2
3
4
// OrderService is the configured service, OrderServiceSoap the endpoint and GetOrder the operation
var result = $Services.OrderService.OrderServiceSoap.GetOrder({
    orderId : $Xml.Evaluate('OrderId')
});

Read values from the response

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
var result = $Services.OrderService.OrderServiceSoap.GetOrder({
    orderId : $Xml.Evaluate('OrderId')
});

// response elements are usually in the service namespace
result.AddNamespace('o', 'http://orders.example.com/');

$Xml.SetValue('OrderStatus', result.Evaluate('o:GetOrderResult/o:Status'));

result.SelectAll('o:GetOrderResult/o:Lines/o:Line', function (line) {
    $Xml.AppendChild('Lines/Line', function (node) {
        node.SetValue('Product', line.Evaluate('o:Product'));
    });
});

Send a SOAP header and set a timeout

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
try {
    var result = $Services.OrderService.OrderServiceSoap.GetOrder({
        orderId : $Xml.Evaluate('OrderId')
    }, {
        ClientInfo : { Application : 'Emakin' }
    }, {
        url : 'https://orders-test.example.com/OrderService.asmx',
        timeout : 30
    });
}
catch (e) {
    console.warn('Order service call failed: ' + e.message);
    throw e;
}

Inspect the request message without calling the service

1
2
3
4
5
6
7
var request = $Services.OrderService.OrderServiceSoap.GetOrder({
    orderId : '1001'
}, null, {
    return : 'request'
});

console.log(request.OuterXml());