or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

client.mdhttp-transport.mdindex.mdsecurity.mdserver.mdwsdl.md
tile.json

tessl/npm-soap

A minimal node SOAP client and server implementation for Node.js applications

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
npmpkg:npm/soap@1.3.x

To install, run

npx @tessl/cli install tessl/npm-soap@1.3.0

index.mddocs/

SOAP

SOAP is a comprehensive SOAP (Simple Object Access Protocol) client and server implementation for Node.js applications. It enables developers to easily connect to web services using SOAP by creating clients from WSDL URLs or local filesystem paths, and also provides server capabilities for hosting SOAP services.

Package Information

  • Package Name: soap
  • Package Type: npm
  • Language: TypeScript/JavaScript
  • Installation: npm install soap

Core Imports

import { createClient, createClientAsync, listen } from "soap";

For CommonJS:

const { createClient, createClientAsync, listen } = require("soap");

Security classes:

import { 
  BasicAuthSecurity, 
  BearerSecurity, 
  WSSecurity,
  ClientSSLSecurity
} from "soap";

Basic Usage

Creating a SOAP Client

import { createClientAsync } from "soap";

// Create client from WSDL URL
const client = await createClientAsync("http://example.com/service.wsdl");

// Call SOAP methods (dynamically generated from WSDL)
const result = await client.SomeMethodAsync({ param1: "value" });
console.log(result);

Creating a SOAP Server

const soap = require("soap");
const http = require("http");

const service = {
  MyService: {
    MyPort: {
      MyFunction: function(args, callback) {
        callback({ result: "Hello " + args.name });
      }
    }
  }
};

const server = http.createServer();
soap.listen(server, "/wsdl", service, xml);
server.listen(8000);

Architecture

SOAP is built around several key components:

  • Client API: createClient and createClientAsync functions for creating SOAP clients from WSDL
  • Server API: listen function for hosting SOAP services on HTTP servers
  • Security System: Multiple authentication mechanisms (Basic Auth, Bearer, SSL, WS-Security, NTLM)
  • HTTP Transport: Configurable HTTP client with proxy support, custom agents, and MTOM attachments
  • WSDL Processing: Complete WSDL parsing, validation, and method generation
  • Event System: EventEmitter-based architecture for request/response monitoring

Capabilities

SOAP Client Operations

Core functionality for creating SOAP clients from WSDL definitions and invoking web service operations with full TypeScript support.

function createClient(
  url: string, 
  callback: (err: any, client: Client) => void, 
  endpoint?: string
): void;

function createClient(
  url: string,
  options: IOptions,  
  callback: (err: any, client: Client) => void,
  endpoint?: string  
): void;

function createClientAsync(
  url: string,
  options?: IOptions,
  endpoint?: string
): Promise<Client>;

SOAP Client

SOAP Server Hosting

Server functionality for hosting SOAP web services on HTTP servers with automatic WSDL generation and request handling.

function listen(
  server: any,
  path: string,
  services: IServices,
  wsdl: string,
  callback?: Function
): Server;

function listen(
  server: any, 
  options: IServerOptions
): Server;

SOAP Server

Security and Authentication

Comprehensive security system supporting multiple authentication mechanisms for enterprise SOAP integration.

class BasicAuthSecurity implements ISecurity {
  constructor(username: string, password: string, defaults?: any);
}

class BearerSecurity implements ISecurity {
  constructor(token: string, defaults?: any);
}

class WSSecurity implements ISecurity {
  constructor(username: string, password: string, options?: any);
}

Security

HTTP Transport and Configuration

HTTP transport layer with support for custom agents, proxies, SSL configuration, and MTOM attachments.

class HttpClient implements IHttpClient {
  request(
    rurl: string,
    data: any,
    callback: (error: any, res?: any, body?: any) => any,
    exheaders?: IHeaders,
    exoptions?: IExOptions,
    caller?: any
  ): any;
  
  requestStream?(
    rurl: string,
    data: any,
    exheaders?: IHeaders,
    exoptions?: IExOptions,
    caller?: any
  ): any;
}

HTTP Transport

WSDL Processing

WSDL parsing, validation, and XML object conversion capabilities for processing web service definitions.

class WSDL {
  constructor(definition: any, uri: string, options: IOptions);
  
  xmlToObject(xml: any, callback?: any): any;
  objectToDocumentXML(name: string, params: any, nsPrefix: string, nsURI?: string, type?: string): any;
  objectToRpcXML(name: string, params: any, nsPrefix: string, nsURI: string, isParts?: boolean): string;
  describeServices(): any;
  toXML(): string;
}

function open_wsdl(uri: any, callback: (error: any, result?: WSDL) => any): any;
function open_wsdl(uri: any, options: IOptions, callback: (error: any, result?: WSDL) => any): any;

WSDL Processing

Utility Functions

Helper functions for XML processing, password hashing, and MTOM attachment handling.

function passwordDigest(nonce: string, created: string, password: string): string;
function xmlEscape(obj: any): any;
function findPrefix(xmlnsMapping: any, nsURI: any): string;
function splitQName<T>(nsName: T): { prefix: string; name: T | string };
function parseMTOMResp(payload: Buffer, boundary: string, callback: (err?: Error, resp?: IMTOMAttachments) => void): Promise<void>;

Types

Core Types

interface IOptions extends IWsdlBaseOptions {
  /** Don't cache WSDL files, request them every time */
  disableCache?: boolean;
  /** Custom cache implementation for WSDLs */
  wsdlCache?: IWSDLCache;
  /** Override the SOAP service's host specified in the .wsdl file */
  endpoint?: string;
  /** Set specific key instead of soap:Body */
  envelopeKey?: string;
  /** Set specific SOAP Schema Url */
  envelopeSoapUrl?: string;
  /** Provide your own http client that implements request interface */
  httpClient?: IHttpClient;
  /** Override the request module with axios instance */
  request?: any;
  /** Enable streaming */
  stream?: boolean;
  /** Return SAX stream instead of parsed object */
  returnSaxStream?: boolean;
  /** Custom deserializer */
  customDeserializer?: any;
  /** Override the default promise suffix from 'Async' */
  overridePromiseSuffix?: string;
  /** Handle MTOM attachments in response */
  parseReponseAttachments?: boolean;
  /** Handle endpoint response encoding when using parseReponseAttachments */
  encoding?: BufferEncoding;
}

interface IWsdlBaseOptions {
  /** XML attributes key */
  attributesKey?: string;
  /** XML value key */
  valueKey?: string;
  /** XML key */
  xmlKey?: string;
  /** Override root element */
  overrideRootElement?: {
    namespace: string;
    xmlnsAttributes?: IXmlAttribute[];
  };
  /** Ignored namespaces configuration */
  ignoredNamespaces?: boolean | string[] | {
    namespaces?: string[];
    override?: boolean;
  };
  /** Ignore base namespaces */
  ignoreBaseNameSpaces?: boolean;
  /** Escape special XML characters in SOAP message */
  escapeXML?: boolean;
  /** Return an Invalid XML SOAP fault on a bad request */
  returnFault?: boolean;
  /** Handle nil as null */
  handleNilAsNull?: boolean;
  /** Replace non-identifier characters with _ */
  normalizeNames?: boolean;
  /** Preserve leading and trailing whitespace characters */
  preserveWhitespace?: boolean;
  /** Support for nonstandard array semantics */
  namespaceArrayElements?: boolean;
  /** Use empty tags */
  useEmptyTag?: boolean;
  /** Strict mode */
  strict?: boolean;
  /** Custom HTTP headers to be sent on WSDL requests */
  wsdl_headers?: { [key: string]: any };
  /** Custom options for the request module on WSDL requests */
  wsdl_options?: { [key: string]: any };
  /** Set proper headers for SOAP v1.2 */
  forceSoap12Headers?: boolean;
}

interface IServices {
  [serviceName: string]: {
    [portName: string]: {
      [methodName: string]: ISoapServiceMethod;
    };
  };
}

interface ISoapServiceMethod {
  (args: any, callback?: (data: any) => void, headers?: any, req?: any, res?: any, sender?: any): any;
}

interface ISecurity {
  addOptions?(options: any): void;
  toXML?(): string;  
  addHeaders?(headers: IHeaders): void;
  postProcess?(xml: any, envelopeKey: any): string;
}

interface IServerOptions extends IWsdlBaseOptions {
  /** URL path for WSDL endpoint */
  path: string | RegExp;
  /** Service implementations */
  services: IServices;
  /** WSDL content or file path */
  xml?: string;
  /** URI path for service operations */
  uri?: string;
  /** Optional completion callback */
  callback?: (err: any, res: any) => void;
  /** Suppress the full stack trace for error messages */
  suppressStack?: boolean;
  /** One-way operation options */
  oneWay?: IOneWayOptions;
  /** Control chunked transfer encoding in response */
  enableChunkedEncoding?: boolean;
}

interface IOneWayOptions {
  /** Response code for one-way operations */
  responseCode?: number;
  /** Send empty body for one-way operations */
  emptyBody?: boolean;
}

interface IHttpClient {
  request(rurl: string, data: any, callback: (error: any, res?: any, body?: any) => any, exheaders?: IHeaders, exoptions?: IExOptions, caller?: any): any;
  requestStream?(rurl: string, data: any, exheaders?: IHeaders, exoptions?: IExOptions, caller?: any): any;
}

interface IHeaders {
  [k: string]: any;
}

interface IExOptions {
  [key: string]: any;
}

interface IXmlAttribute {
  name: string;
  value: string;
}

interface IMTOMAttachments {
  parts: Array<{
    body: Buffer;
    headers: { [key: string]: string };
  }>;
}

interface IWSDLCache {
  has(key: string): boolean;
  get(key: string): WSDL;
  set(key: string, wsdl: WSDL): void;
}

type ServerType = any;

type SoapMethod = (args: any, callback: (err: any, result: any, rawResponse: any, soapHeader: any, rawRequest: any, mtomAttachments?: IMTOMAttachments) => void, options?: any, extraHeaders?: any, mtomAttachments?: IMTOMAttachments) => void;

type SoapMethodAsync = (args: any, options?: any, extraHeaders?: any) => Promise<[any, any, any, any, IMTOMAttachments?]>;

interface ISoapFaultError {
  Fault: ISoapFault;
}

type ISoapFault = ISoapFault11 | ISoapFault12;

interface ISoapFault11 {
  faultcode: number | string;
  faultstring: string;
  detail?: string;
  statusCode?: number;
}

interface ISoapFault12 {
  Code: {
    Value: string;
    Subcode?: {
      Value: string;
    };
  };
  Reason: {
    Text: string;
  };
  statusCode?: number;
}