A minimal node SOAP client and server implementation for Node.js applications
—
WSDL (Web Services Description Language) parsing, validation, and XML object conversion capabilities for processing web service definitions. The WSDL class provides comprehensive functionality for working with SOAP service definitions.
Core WSDL processing class for parsing service definitions and handling XML transformations.
/**
* WSDL class for parsing and processing web service definitions
* Handles WSDL parsing, XML object conversion, and service description
*/
class WSDL {
/** Ignored namespaces array */
ignoredNamespaces: string[];
/** Whether to ignore base namespaces */
ignoreBaseNameSpaces: boolean;
/** Key used for XML values */
valueKey: string;
/** Key used for XML content */
xmlKey: string;
/** XML namespace for envelope */
xmlnsInEnvelope: string;
/** XML namespace for header */
xmlnsInHeader: string;
/** WSDL URI */
uri: string;
/** WSDL definitions element */
definitions: any;
/** WSDL processing options */
options: any;
/**
* Create new WSDL instance
* @param definition - WSDL definition content or service object
* @param uri - Base URI for the WSDL
* @param options - WSDL processing options
*/
constructor(definition: any, uri: string, options: IOptions);
}Core methods for WSDL processing and XML conversion.
/**
* Set callback for when WSDL is ready
* @param callback - Callback function called when WSDL processing is complete
*/
onReady(callback: (err: Error) => void): void;
/**
* Process WSDL includes and imports
* @param callback - Callback function for completion
*/
processIncludes(callback: any): void;
/**
* Get description of all services in the WSDL
* @returns Object describing services, ports, and operations
*/
describeServices(): any;
/**
* Convert WSDL to XML string representation
* @returns XML string of the WSDL
*/
toXML(): string;
/**
* Convert XML to JavaScript object
* @param xml - XML content to convert
* @param callback - Optional callback for asynchronous processing
* @returns Parsed JavaScript object
*/
xmlToObject(xml: any, callback?: any): any;
/**
* Find schema object by namespace URI and qualified name
* @param nsURI - Namespace URI
* @param qname - Qualified name to find
* @returns Schema object definition
*/
findSchemaObject(nsURI: string, qname: string): any;
/**
* Create document-style XML from parameters
* @param name - Element name
* @param params - Parameters object
* @param nsPrefix - Namespace prefix
* @param nsURI - Namespace URI
* @param type - Type information
* @returns Generated XML string
*/
objectToDocumentXML(name: string, params: any, nsPrefix: string, nsURI?: string, type?: string): any;
/**
* Create RPC-style XML from parameters
* @param name - Operation name
* @param params - Parameters object
* @param nsPrefix - Namespace prefix
* @param nsURI - Namespace URI
* @param isParts - Whether to use parts format
* @returns Generated XML string
*/
objectToRpcXML(name: string, params: any, nsPrefix: string, nsURI: string, isParts?: boolean): string;
/**
* Convert JavaScript object to XML with namespace handling
* @param obj - Object to convert
* @param name - Element name
* @param nsPrefix - Namespace prefix
* @param nsURI - Namespace URI
* @param isFirst - Whether this is the first element
* @param xmlnsAttr - XML namespace attributes
* @param schemaObject - Schema object for validation
* @param nsContext - Namespace context
* @returns Generated XML
*/
objectToXML(obj: any, name: string, nsPrefix: any, nsURI: string, isFirst?: boolean, xmlnsAttr?: any, schemaObject?: any, nsContext?: any): any;
/**
* Check if namespace should be ignored
* @param ns - Namespace to check
* @returns True if namespace should be ignored
*/
isIgnoredNameSpace(ns: string): boolean;
/**
* Filter out ignored namespace from string
* @param ns - Namespace string
* @returns Filtered namespace string
*/
filterOutIgnoredNameSpace(ns: string): string;
/**
* Find schema type definition
* @param name - Type name
* @param nsURI - Namespace URI
* @returns Schema type definition
*/
findSchemaType(name: any, nsURI: any): any;
/**
* Find child schema object
* @param parameterTypeObj - Parameter type object
* @param childName - Child element name
* @param backtrace - Backtrace for debugging
* @returns Child schema object
*/
findChildSchemaObject(parameterTypeObj: any, childName: any, backtrace?: any): any;Usage Examples:
import { WSDL, open_wsdl } from "soap";
// Create WSDL from definition
const wsdl = new WSDL(wsdlDefinition, 'http://example.com/service', {
strict: true,
preserveWhitespace: false
});
// Wait for WSDL to be ready
wsdl.onReady((err) => {
if (err) throw err;
// Get service descriptions
const services = wsdl.describeServices();
console.log('Available services:', Object.keys(services));
// Convert to XML
const xmlString = wsdl.toXML();
console.log('WSDL XML:', xmlString);
});
// Convert object to document XML
const docXml = wsdl.objectToDocumentXML(
'GetUserRequest',
{ userId: 123 },
'tns',
'http://example.com/types'
);
// Convert object to RPC XML
const rpcXml = wsdl.objectToRpcXML(
'GetUser',
{ userId: 123 },
'tns',
'http://example.com/service'
);Functions for opening and processing WSDL from various sources.
/**
* Open and parse WSDL from URL or file path
* @param uri - WSDL URL or file path
* @param callback - Callback receiving (error, wsdl)
*/
function open_wsdl(uri: any, callback: (error: any, result?: WSDL) => any): any;
/**
* Open and parse WSDL from URL or file path with options
* @param uri - WSDL URL or file path
* @param options - WSDL processing options
* @param callback - Callback receiving (error, wsdl)
*/
function open_wsdl(uri: any, options: IOptions, callback: (error: any, result?: WSDL) => any): any;Usage Examples:
import { open_wsdl } from "soap";
// Open WSDL from URL
open_wsdl('http://example.com/service.wsdl', (err, wsdl) => {
if (err) throw err;
console.log('WSDL loaded successfully');
const services = wsdl.describeServices();
console.log('Services:', services);
});
// Open WSDL with options
open_wsdl('http://example.com/service.wsdl', {
strict: true,
ignoreBaseNameSpaces: false,
wsdl_headers: { 'User-Agent': 'SOAP Client' }
}, (err, wsdl) => {
if (err) throw err;
// Process WSDL includes
wsdl.processIncludes((includeErr) => {
if (includeErr) throw includeErr;
console.log('WSDL includes processed');
});
});
// Open from local file
open_wsdl('./local-service.wsdl', (err, wsdl) => {
if (err) throw err;
// Convert object to XML using WSDL schema
const xml = wsdl.objectToDocumentXML(
'CalculateRequest',
{ a: 10, b: 20 },
'calc',
'http://calculator.example.com/'
);
console.log('Generated XML:', xml);
});WSDL class provides sophisticated namespace handling capabilities.
// Check if namespace should be ignored
const shouldIgnore = wsdl.isIgnoredNameSpace('http://schemas.xmlsoap.org/soap/envelope/');
// Filter namespace prefixes
const filtered = wsdl.filterOutIgnoredNameSpace('soap:Body');
// Find schema objects with namespace resolution
const userType = wsdl.findSchemaObject('http://example.com/types', 'User');Work with XSD schema definitions embedded in WSDL.
// Find specific schema type
const stringType = wsdl.findSchemaType('string', 'http://www.w3.org/2001/XMLSchema');
// Find child elements in complex types
const childElement = wsdl.findChildSchemaObject(userType, 'name');Control XML generation behavior through WSDL options.
const wsdl = new WSDL(definition, uri, {
// Use empty tags for null values
useEmptyTag: true,
// Preserve whitespace in text content
preserveWhitespace: true,
// Handle namespace arrays properly
namespaceArrayElements: false,
// Custom attribute key
attributesKey: '$attributes',
// Custom value key
valueKey: '$value'
});Handle WSDL processing errors appropriately.
wsdl.onReady((err) => {
if (err) {
console.error('WSDL processing failed:', err.message);
return;
}
try {
const xml = wsdl.objectToDocumentXML('InvalidElement', {}, 'ns', 'uri');
} catch (conversionError) {
console.error('XML conversion failed:', conversionError.message);
}
});Install with Tessl CLI
npx tessl i tessl/npm-soap