strong-soap: Node.js SOAP Client and Server

5.0.9 · active · verified Tue Apr 21

strong-soap provides a comprehensive Node.js module for interacting with SOAP web services, offering both client capabilities for invoking services and a mock-up server for testing. Currently at version 5.0.9, it maintains an active development pace with frequent patch and minor updates, typically on a monthly or bi-monthly schedule, and major versions released approximately annually to biennially, often aligning with Node.js version support. The library is built upon the `node-soap` module and distinguishes itself by supporting both RPC and Document styles, as well as SOAP 1.1 and 1.2 Faults. It includes utility APIs for converting XML to JSON and vice versa, describing WSDL documents, and handling both synchronous and asynchronous service method calls. A key feature is its built-in WS-Security support, specifically for UsernameToken and PasswordText encoding, enhancing its utility for enterprise integrations.

Common errors

Warnings

Install

Imports

Quickstart

This example demonstrates how to create a SOAP client from a WSDL URL and invoke a method (GetQuote) on a public stock quote web service. It highlights asynchronous client creation and method invocation using Promises for modern JavaScript patterns, showing how to pass arguments and handle responses or errors.

import { soap } from 'strong-soap';
import * as path from 'path';

// A public WSDL for a stock quote service
const wsdlUrl = 'http://www.webservicex.net/stockquote.asmx?WSDL';

async function getStockQuote(symbol) {
  return new Promise((resolve, reject) => {
    soap.createClient(wsdlUrl, {}, (err, client) => {
      if (err) {
        return reject(new Error(`Failed to create SOAP client: ${err.message}`));
      }

      // Describe the service to see available methods and their signatures
      // console.log('Service Description:', client.describe());

      // Invoke the GetQuote method. The method structure might be nested
      // depending on the WSDL (e.g., client.Service.Port.Method)
      const serviceMethod = client.StockQuote.StockQuoteSoap.GetQuote;

      const requestArgs = {
        symbol: symbol
      };

      serviceMethod(requestArgs, (err, result, envelope, soapHeader) => {
        if (err) {
          console.error('SOAP Request Error:', err.message);
          // Log SOAP envelope for debugging if available
          if (client.lastRequest) {
            console.error('Last SOAP Request Envelope:\n', client.lastRequest);
          }
          return reject(err);
        }

        console.log(`Successfully fetched quote for ${symbol}`);
        console.log('Result:', JSON.stringify(result, null, 2));
        // console.log('Full SOAP Envelope:\n', envelope);
        resolve(result);
      });
    });
  });
}

(async () => {
  try {
    console.log('Fetching stock quote for IBM...');
    await getStockQuote('IBM');
    console.log('\nFetching stock quote for GOOG...');
    await getStockQuote('GOOG');
  } catch (error) {
    console.error('Application Error:', error);
  }
})();

view raw JSON →