Node.js SOAP Client and Server

1.9.1 · active · verified Tue Apr 21

Node-SOAP is a robust and minimal JavaScript library designed for interacting with SOAP web services, offering both client-side and server-side functionalities. Currently at stable version 1.9.1, the project maintains a regular release cadence focused on dependency updates, security patches, and minor enhancements, typically releasing new versions every few weeks or months. Its key differentiators include comprehensive support for various SOAP security mechanisms such as BasicAuth, WS-Security, and NTLM, and a flexible API that supports both callback-based and modern promise-based interactions with WSDL-defined services. The library ships with TypeScript types, making it well-suited for contemporary Node.js applications. It targets Node.js versions 20.19.0 and higher.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates asynchronous SOAP client creation, calling a service method (Add), and basic error handling with security options.

import { createClientAsync, BasicAuthSecurity, Client } from 'soap';

async function consumeWebService() {
  const wsdlUrl = 'http://www.dneonline.com/calculator.asmx?WSDL'; // Public test WSDL
  let client: Client | undefined;
  try {
    client = await createClientAsync(wsdlUrl);
    console.log('SOAP client initialized successfully.');

    // Optional: Add security headers if required by the service
    // client.setSecurity(new BasicAuthSecurity('username', 'password'));

    // You can inspect available methods and types:
    // console.log(client.describe());

    // Call a method, e.g., 'Add' from the Calculator service
    const args = { intA: 10, intB: 5 };
    console.log(`Calling 'Add' method with arguments: ${JSON.stringify(args)}`);
    const result = await client.AddAsync(args);

    console.log('Result from SOAP service (Add):', result[0].AddResult);
  } catch (error) {
    console.error('Error consuming SOAP web service:', error instanceof Error ? error.message : error);
    // For detailed debugging, inspect the last request/response
    if (client) {
      console.error('Last Request (XML):', client.lastRequest);
      console.error('Last Response (XML):', client.lastResponse);
    }
  }
}

consumeWebService();

view raw JSON →