Toggle menu

strong-soap

This module lets you connect to web services using SOAP.

This library is distributed under the MIT license, its source and full documentation can be found at www.npmjs.com/package/strong-soap (opens new window).

Executed

Server-side

Details

var soap = require('strong-soap').soap;

This module behaves asynchronously. When used in an End Point you will need to use the synchronise module so that it behaves in a synchronous manner.

The first step in using the module is to create a client, providing a URL or filepath to a WSDL that describes the SOAP endpoint as the first argument to soap.createClient. This client object contains the methods defined in the WSDL as functions with the same name.

For example, if the WSDL defines a method called testMethod, this method may be invoked via client.testMethod([...]). Calling these methods with suitable parameters will cause the library to transform the given JSON arguments into XML and perform a SOAP request to the method, as defined in the WSDL.

Example

This example calls the US National Weather Service and returns the forecast for Beverly Hills. Note how a timeout is passed in with the request. Any of the options present in the request module can be added in the same way.

function(params, credentials) {
    var soap = require('strong-soap').soap,
        sync = require('synchronize'),
        result = null,
        soapEndpointURL = "https://graphical.weather.gov/xml/SOAP_server/ndfdXMLserver.php?wsdl",
        // Parse the WDSL and create the soap client
        client = sync.await(soap.createClient(soapEndpointURL, {}, sync.defer()));
    try {
        // Synchronously execute request 
        result = sync.await(client.NDFDgen({
            "latitude": "34.0995",
            "longitude": "-118.414",
            "product": "glance",
            "startTime": "2019-08-13T00:00:00",
            "endTime": "2019-08-13T23:00:00",
            "Unit": "m"
        }, {
            "timeout": 5000
        }, sync.defer()));
    } catch (e) {
        result = e.message;
    }
    return result;
}

Last modified on March 10, 2020

Share this page

Facebook icon Twitter icon email icon

Print

print icon