soap-x509-http
raw JSON → 1.0.2 verified Sat Apr 25 auth: no javascript maintenance
An HTTP client for node-soap that supports X.509 certificate authentication and signing, based on ws.js. Version 1.0.2 is the latest stable release, last updated in 2016. It extends the default HTTP client of node-soap to use TLS client certificates and XML signing. This package is for Node.js only and requires both 'soap' and 'ws' as peer dependencies. Alternatives include custom HTTP clients for node-soap using native TLS, but this package provides integrated signing and certificate support.
Common errors
error Cannot find module 'ws' ↓
cause Peer dependency 'ws' is not installed automatically by npm/yarn.
fix
Run 'npm install ws' or 'yarn add ws'.
error Error: Unable to parse WSDL ↓
cause WSDL file path is incorrect or the file is malformed.
fix
Check the path and contents of the .wsdl file.
error TypeError: X509HttpClient is not a constructor ↓
cause Using ESM import instead of require(). The package exports the constructor as module.exports.
fix
Use 'const X509HttpClient = require("soap-x509-http");'
Warnings
breaking Request signing with the second argument (signingCredentials) may be required, without it the client may not work correctly for WS-Security. ↓
fix Always provide the signingCredentials object with a 'key' property for xml signing.
gotcha The package depends on the 'ws' package (ws.js) which is unmaintained and has known issues with newer Node.js versions. ↓
fix Consider alternative solutions like using a custom HTTP client with native TLS and xml-crypto directly.
gotcha TLS options like pfx, passphrase, ca are passed directly to Node.js https module. Some options may behave differently across Node versions. ↓
fix Refer to Node.js https.request options documentation for each Node version.
Install
npm install soap-x509-http yarn add soap-x509-http pnpm add soap-x509-http Imports
- X509HttpClient wrong
import X509HttpClient from 'soap-x509-http';correctconst X509HttpClient = require('soap-x509-http'); - X509HttpClient wrong
const X509 = require('soap-x509-http').X509HttpClient;correctconst { X509HttpClient } = require('soap-x509-http'); - X509HttpClient wrong
const X509HttpClient = require('soap-x509-http').default;correctconst X509HttpClient = require('soap-x509-http');
Quickstart
const fs = require('fs');
const soap = require('soap');
const X509HttpClient = require('soap-x509-http');
const myX509Client = new X509HttpClient(
{
pfx: fs.readFileSync('./client.pfx'),
passphrase: 'password',
rejectUnauthorized: false,
},
{
key: fs.readFileSync('./client-key.pem'),
}
);
soap.createClient('./service.wsdl', { httpClient: myX509Client }, (err, client) => {
if (err) return console.error(err);
client.MyFunction({ name: 'test' }, (err, result) => {
console.log(result);
});
});