Installations
npm install soap
Developer Guide
Typescript
Yes
Module System
CommonJS
Min. Node Version
>=14.0.0
Node Version
20.18.0
NPM Version
10.8.2
Score
60.3
Supply Chain
97.7
Quality
90.1
Maintenance
100
Vulnerability
98.9
License
Releases
Contributors
Unable to fetch Contributors
Languages
JavaScript (59.23%)
TypeScript (40.77%)
Developer
vpulim
Download Statistics
Total Downloads
80,309,133
Last Day
14,194
Last Week
272,687
Last Month
1,680,244
Last Year
19,369,985
GitHub Statistics
2,996 Stars
1,066 Commits
1,499 Forks
110 Watching
10 Branches
324 Contributors
Package Meta Information
Latest Version
1.1.7
Package Id
soap@1.1.7
Unpacked Size
444.94 kB
Size
92.18 kB
File Count
65
NPM Version
10.8.2
Node Version
20.18.0
Publised On
11 Dec 2024
Total Downloads
Cumulative downloads
Total Downloads
80,309,133
Last day
-82.7%
14,194
Compared to previous day
Last week
-34.1%
272,687
Compared to previous week
Last month
-12.4%
1,680,244
Compared to previous month
Last year
7.1%
19,369,985
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Soap
A SOAP client and server for node.js.
This module lets you connect to web services using SOAP. It also provides a server that allows you to run your own SOAP services.
- Features:
- Install
- Support
- Module
- soap.createClient(url[, options], callback) - create a new SOAP client from a WSDL url. Also supports a local filesystem path.
- soap.createClientAsync(url[, options]) - create a new SOAP client from a WSDL url. Also supports a local filesystem path.
- soap.listen(server, path, services, wsdl, callback) - create a new SOAP server that listens on path and provides services.
- soap.listen(server, options) - create a new SOAP server that listens on path and provides services.
- Server Logging
- Server Events
- Server Response on one-way calls
- SOAP Fault
- Server security example using PasswordDigest
- Server connection authorization
- SOAP Headers
- Client
- Client.describe() - description of services, ports and methods as a JavaScript object
- Client.setSecurity(security) - use the specified security protocol
- Client.method(args, callback, options) - call method on the SOAP service.
- Client.methodAsync(args, options) - call method on the SOAP service.
- Client.service.port.method(args, callback[, options[, extraHeaders]]) - call a method using a specific service and port
- Overriding the namespace prefix
- Client.lastRequest - the property that contains last full soap request for client logging
- Client.setEndpoint(url) - overwrite the SOAP service endpoint address
- Client Events
- request
- message
- soapError
- response
- WSDL
- WSDL.constructor(wsdl, baseURL, options):
- Security
- Handling XML Attributes, Value and XML (wsdlOptions).
- Handling "ignored" namespaces
- Handling "ignoreBaseNameSpaces" attribute
- soap-stub
- Contributors
Features:
- Very simple API
- Handles both RPC and Document schema types
- Supports multiRef SOAP messages (thanks to @kaven276)
- Support for both synchronous and asynchronous method handlers
- WS-Security UsernameToken Profile 1.0
- Supports Express based web server (body parser middleware can be used)
Install
npm install soap
Support
Community support is available through GitHub issues tab. Paid support can be provided as well, please contact one of the active maintainers.
Module
soap.createClient(url[, options], callback) - create a new SOAP client from a WSDL url. Also supports a local filesystem path.
url
(string): A HTTP/HTTPS URL, XML or a local filesystem path.options
(Object):endpoint
(string): Override the host specified by the SOAP service in the WSDL file.envelopeKey
(string): Set a custom envelope key. (Default:'soap'
)preserveWhitespace
(boolean): Preserve any leading and trailing whitespace characters in text and cdata.escapeXML
(boolean): Escape special XML characters (e.g.&
,>
,<
etc) in SOAP messages. (Default:true
)suppressStack
(boolean): Suppress the full stack trace for error messages.returnFault
(boolean): Return anInvalid XML
SOAP fault upon a bad request. (Default:false
)forceSoap12Headers
(boolean): Enable SOAP 1.2 compliance.httpClient
(Object): Override the built-in HttpClient object with your own. Must implementrequest(rurl, data, callback, exheaders, exoptions)
.request
(Object): Override the default request module (Axios as ofv0.40.0
).wsdl_headers
(Object): Set HTTP headers with values to be sent on WSDL requests.wsdl_options
(Object): Set options for the request module on WSDL requests. If using the default request module, see Request Config | Axios Docs.disableCache
(boolean): Prevents caching WSDL files and option objects.wsdlCache
(IWSDLCache): Custom cache implementation. If not provided, defaults to caching WSDLs indefinitely.overridePromiseSuffix
(string): Override the default method name suffix of WSDL operations for Promise-based methods. If any WSDL operation name ends withAsync', you must use this option. (**Default:**
Async`)normalizeNames
(boolean): Replace non-identifier characters ([^a-z$_0-9]
) with_
in WSDL operation names. Note: Clients using WSDLs with two operations likesoap:method
andsoap-method
will be overwritten. In this case, you must use bracket notation instead (client['soap:method']()
).namespaceArrayElements
(boolean): Support non-standard array semantics. JSON arrays of the form{list: [{elem: 1}, {elem: 2}]}
will be marshalled into XML as<list><elem>1</elem></list> <list><elem>2</elem></list>
. Iffalse
, it would be marshalled into<list> <elem>1</elem> <elem>2</elem> </list>
. (Default:true
)stream
(boolean): Use streams to parse the XML SOAP responses. (Default:false
)returnSaxStream
(boolean): Return the SAX stream, transferring responsibility of parsing XML to the end user. Only valid when the stream option is set totrue
. (Default:false
)parseReponseAttachments
(boolean): Treat response as multipart/related response with MTOM attachment. Reach attachments on thelastResponseAttachments
property of SoapClient. (Default:false
)
callback
(Function):err
(Error |) result
(Any)
- Returns:
Client
Example
HTTP/HTTPS:
1 var soap = require('soap'); 2 var url = 'http://example.com/wsdl?wsdl'; 3 var args = {name: 'value'}; 4 5 soap.createClient(url, {}, function(err, client) { 6 client.MyFunction(args, function(err, result) { 7 console.log(result); 8 }); 9 });
XML string format:
1 var soap = require('soap'); 2 var xml = ` 3 <?xml version="1.0" encoding="UTF-8"?> 4 <definitions xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"> 5 <message name="MyFunctionRequest"/> 6 <message name="MyFunctionResponse"/> 7 8 <portType name="MyFunctionPortType"> 9 <operation name="MyFunction"> 10 <input message="MyFunctionRequest"/> 11 <output message="MyFunctionResponse"/> 12 </operation> 13 </portType> 14 15 <binding name="MyFunctionBinding" type="MyFunctionPortType"> 16 <soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/> 17 <operation name="MyFunction"> 18 <soap:operation soapAction="MyFunction"/> 19 <input><soap:body use="encoded"/></input> 20 <output><soap:body use="encoded"/></output> 21 </operation> 22 </binding> 23 24 <service name="MyService"> 25 <port binding="MyFunctionBinding" name="MyFunctionPort"> 26 <soap:address location="http://www.examples.com/MyFunction/" /> 27 </port> 28 </service> 29 </definitions> 30 `; 31 var args = {name: 'value'}; 32 33 soap.createClient(xml, {}, function(err, client) { 34 client.MyFunction(args, function(err, result) { 35 console.log(result); 36 }); 37 });
Note: for versions of node >0.10.X, you may need to specify {connection: 'keep-alive'}
in SOAP headers to avoid truncation of longer chunked responses.
soap.createClientAsync(url[, options]) - create a new SOAP client from a WSDL url. Also supports a local filesystem path.
Construct a Promise<Client>
with the given WSDL file.
url
(string): A HTTP/HTTPS URL, XML or a local filesystem path.options
(Object): See soap.createClient(url[, options], callback) for a description.- Returns:
Promise<Client>
Example
1 var soap = require('soap'); 2 var url = 'http://example.com/wsdl?wsdl'; 3 var args = {name: 'value'}; 4 5 // then/catch 6 soap.createClientAsync(url).then((client) => { 7 return client.MyFunctionAsync(args); 8 }).then((result) => { 9 console.log(result); 10 }); 11 12 // async/await 13 var client = await soap.createClientAsync(url); 14 var result = await client.MyFunctionAsync(args); 15 console.log(result[0]);
Note: for versions of node >0.10.X, you may need to specify {connection: 'keep-alive'}
in SOAP headers to avoid truncation of longer chunked responses.
soap.listen(server, path, services, wsdl, callback) - create a new SOAP server that listens on path and provides services.
soap.listen(server, options) - create a new SOAP server that listens on path and provides services.
server
(Object): A http server or Express framework based server.path
(string)options
(Object): An object containing server options and WSDL Optionspath
(string)services
(Object)xml
(string)uri
(string)pfx
(string | Buffer): The private key, certificate and CA certs of the server in PFX or PKCS12 format. (Mutually exclusive with the key, cert and ca options.)key
(string | Buffer): The private key of the server in PEM format. (Could be an array of keys). (Required)passphrase
(string): The passphrase for the private key or pfx.cert
(string | Buffer): The certificate key of the server in PEM format. (Could be an array of certs). (Required)ca
(string[] | Buffer[]): Trusted certificates in PEM format. If this is omitted several well known "root" CAs will be used, like VeriSign. These are used to authorize connections.crl
(string | string[]: PEM encoded CRLs (Certificate Revocation List)ciphers
(string): A description of the ciphers to use or exclude, separated by:
. The default cipher suite is:enableChunkedEncoding
(boolean): Controls chunked transfer encoding in response. Some clients (such as Windows 10's MDM enrollment SOAP client) are sensitive to transfer-encoding mode and can't accept chunked response. This option lets users disable chunked transfer encoding for such clients. (Default:true
)
services
(Object)wsdl
(string): An XML string that defines the service.callback
(Function): A function to run after the server has been initialized.- Returns:
Server
Example
1 var myService = { 2 MyService: { 3 MyPort: { 4 MyFunction: function(args) { 5 return { 6 name: args.name 7 }; 8 }, 9 10 // This is how to define an asynchronous function with a callback. 11 MyAsyncFunction: function(args, callback) { 12 // do some work 13 callback({ 14 name: args.name 15 }); 16 }, 17 18 // This is how to define an asynchronous function with a Promise. 19 MyPromiseFunction: function(args) { 20 return new Promise((resolve) => { 21 // do some work 22 resolve({ 23 name: args.name 24 }); 25 }); 26 }, 27 28 // This is how to receive incoming headers 29 HeadersAwareFunction: function(args, cb, headers) { 30 return { 31 name: headers.Token 32 }; 33 }, 34 35 // You can also inspect the original `req` 36 reallyDetailedFunction: function(args, cb, headers, req) { 37 console.log('SOAP `reallyDetailedFunction` request from ' + req.connection.remoteAddress); 38 return { 39 name: headers.Token 40 }; 41 } 42 } 43 } 44 }; 45 46 var xml = require('fs').readFileSync('myservice.wsdl', 'utf8'); 47 48 //http server example 49 var server = http.createServer(function(request,response) { 50 response.end('404: Not Found: ' + request.url); 51 }); 52 53 server.listen(8000); 54 soap.listen(server, '/wsdl', myService, xml, function(){ 55 console.log('server initialized'); 56 }); 57 58 //express server example 59 var app = express(); 60 //body parser middleware are supported (optional) 61 app.use(bodyParser.raw({type: function(){return true;}, limit: '5mb'})); 62 app.listen(8001, function(){ 63 //Note: /wsdl route will be handled by soap module 64 //and all other routes & middleware will continue to work 65 soap.listen(app, '/wsdl', myService, xml, function(){ 66 console.log('server initialized'); 67 }); 68 }); 69
1var xml = require('fs').readFileSync('myservice.wsdl', 'utf8'); 2 3soap.listen(server, { 4 // Server options. 5 path: '/wsdl', 6 services: myService, 7 xml: xml, 8 9 // WSDL options. 10 attributesKey: 'theAttrs', 11 valueKey: 'theVal', 12 xmlKey: 'theXml' 13});
Server Logging
If the log
method is defined, it will be called with:
type
: 'received', 'replied', 'info' or 'error'.data
: The data to be logged which will be an XML for 'received' and 'replied' or a message for the other types.req
: The original request object
1 server = soap.listen(...) 2 server.log = function(type, data, req) { 3 // type is 'received', 'replied', 'info' or 'error' 4 };
Server Events
Server instances emit the following events:
- request - Emitted for every received messages.
The signature of the callback is
function(request, methodName)
. - response - Emitted before sending SOAP response.
The signature of the callback is
function(response, methodName)
. - headers - Emitted when the SOAP Headers are not empty.
The signature of the callback is
function(headers, methodName)
.
The sequence order of the calls is request
, headers
and then the dedicated
service method.
Server Response on one-way calls
The so called one-way (or asynchronous) calls occur when an operation is called with no output defined in WSDL. The server sends a response (defaults to status code 200 with no body) to the client disregarding the result of the operation.
You can configure the response to match the appropriate client expectation to the SOAP standard implementation.
Pass in oneWay
object in server options. Use the following keys:
emptyBody
: if true, returns an empty body, otherwise no content at all (default is false)
responseCode
: default statusCode is 200, override it with this options (for example 202 for SAP standard compliant response)
SOAP Fault
A service method can reply with a SOAP Fault to a client by throw
ing an
object with a Fault
property.
1 throw { 2 Fault: { 3 Code: { 4 Value: 'soap:Sender', 5 Subcode: { value: 'rpc:BadArguments' } 6 }, 7 Reason: { Text: 'Processing Error' } 8 } 9 };
To change the HTTP statusCode of the response include it on the fault. The statusCode property will not be put on the xml message.
1 throw { 2 Fault: { 3 Code: { 4 Value: 'soap:Sender', 5 Subcode: { value: 'rpc:BadArguments' } 6 }, 7 Reason: { Text: 'Processing Error' }, 8 statusCode: 500 9 } 10 };
Server security example using PasswordDigest
If server.authenticate
is not defined then no authentication will take place.
Asynchronous authentication:
1 server = soap.listen(...) 2 server.authenticate = function(security, callback) { 3 var created, nonce, password, user, token; 4 token = security.UsernameToken, user = token.Username, 5 password = token.Password, nonce = token.Nonce, created = token.Created; 6 7 myDatabase.getUser(user, function (err, dbUser) { 8 if (err || !dbUser) { 9 callback(false); 10 return; 11 } 12 13 callback(password === soap.passwordDigest(nonce, created, dbUser.password)); 14 }); 15 };
Synchronous authentication:
1 server = soap.listen(...) 2 server.authenticate = function(security) { 3 var created, nonce, password, user, token; 4 token = security.UsernameToken, user = token.Username, 5 password = token.Password, nonce = token.Nonce, created = token.Created; 6 return user === 'user' && password === soap.passwordDigest(nonce, created, 'password'); 7 };
Server connection authorization
The server.authorizeConnection
method is called prior to the soap service method.
If the method is defined and returns false
then the incoming connection is
terminated.
1 server = soap.listen(...) 2 server.authorizeConnection = function(req) { 3 return true; // or false 4 };
SOAP Headers
Received SOAP Headers
A service method can look at the SOAP headers by providing a 3rd arguments.
1 { 2 HeadersAwareFunction: function(args, cb, headers) { 3 return { 4 name: headers.Token 5 }; 6 } 7 }
It is also possible to subscribe to the 'headers' event. The event is triggered before the service method is called, and only when the SOAP Headers are not empty.
1 server = soap.listen(...) 2 server.on('headers', function(headers, methodName) { 3 // It is possible to change the value of the headers 4 // before they are handed to the service method. 5 // It is also possible to throw a SOAP Fault 6 });
First parameter is the Headers object; second parameter is the name of the SOAP method that will called (in case you need to handle the headers differently based on the method).
Outgoing SOAP Headers
Both client & server can define SOAP headers that will be added to what they send. They provide the following methods to manage the headers.
addSoapHeader(soapHeader[, name, namespace, xmlns]) - add soapHeader to soap:Header node
Parameters
soapHeader
Object({rootName: {name: 'value'}}), strict xml-string, or function (server only)
For servers only, soapHeader
can be a function, which allows headers to be
dynamically generated from information in the request. This function will be
called with the following arguments for each received request:
methodName
The name of the request methodargs
The arguments of the requestheaders
The headers in the requestreq
The original request object
The return value of the function must be an Object({rootName: {name: 'value'}}) or strict xml-string, which will be inserted as an outgoing header of the response to that request.
For example:
1 server = soap.listen(...); 2 server.addSoapHeader(function(methodName, args, headers, req) { 3 console.log('Adding headers for method', methodName); 4 return { 5 MyHeader1: args.SomeValueFromArgs, 6 MyHeader2: headers.SomeRequestHeader 7 }; 8 // or you can return "<MyHeader1>SomeValue</MyHeader1>" 9 });
Returns
The index where the header is inserted.
Optional parameters when first arg is object :
name
Unknown parameter (it could just a empty string)namespace
prefix of xml namespacexmlns
URI
changeSoapHeader(index, soapHeader[, name, namespace, xmlns]) - change an already existing soapHeader
Parameters
index
index of the header to replace with provided new valuesoapHeader
Object({rootName: {name: 'value'}}), strict xml-string or function (server only)
See addSoapHeader
for how to pass a function into soapHeader
.
getSoapHeaders() - return all defined headers
clearSoapHeaders() - remove all defined headers
Client
An instance of Client
is passed to the soap.createClient
callback. It is used to execute methods on the soap service.
Client.describe() - description of services, ports and methods as a JavaScript object
1 client.describe() // returns 2 { 3 MyService: { 4 MyPort: { 5 MyFunction: { 6 input: { 7 name: 'string' 8 } 9 } 10 } 11 } 12 }
Client.setSecurity(security) - use the specified security protocol
See Security for example usage.
Client.method(args, callback, options) - call method on the SOAP service.
args
(Object): Arguments that generate an XML document inside of the SOAP Body section.callback
(Function)options
(Object): Set options for the request module on WSDL requests. If using the default request module, see Request Config | Axios Docs. Additional options supported bynode-soap
are documented below:forever
(boolean): Enables keep-alive connections and pools themattachments
(Array): array of attachment objects. This converts the request into MTOM: headers['Content-Type']='multipart/related; type="application/xop+xml"; start= ... '
[{ mimetype: content mimetype, contentId: part id, name: file name, body: binary data }, ... ]
forceMTOM
(boolean): Send the request as MTOM even if you don't have attachments.forceGzip
(boolean): Force transfer-encoding in gzip. (Default:false
)
Example
1 client.MyFunction({name: 'value'}, function(err, result, rawResponse, soapHeader, rawRequest) { 2 // result is a javascript object 3 // rawResponse is the raw xml response string 4 // soapHeader is the response soap header as a javascript object 5 // rawRequest is the raw xml request string 6 })
Client.methodAsync(args, options) - call method on the SOAP service.
args
(Object): Arguments that generate an XML document inside of the SOAP Body section.options
(Object): See Client.method(args, callback, options) - call method on the SOAP service. for a description.
Example
1 client.MyFunctionAsync({name: 'value'}).then((result) => { 2 // result is a javascript array containing result, rawResponse, soapheader, and rawRequest 3 // result is a javascript object 4 // rawResponse is the raw xml response string 5 // soapHeader is the response soap header as a javascript object 6 // rawRequest is the raw xml request string 7 })
Example with JSON for the args
The example above uses {name: 'value'}
as the args. This may generate a SOAP messages such as:
1<?xml version="1.0" encoding="utf-8"?> 2<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 3 <soapenv:Body> 4 <Request xmlns="http://www.example.com/v1"> 5 <name>value</name> 6 </Request> 7 </soapenv:Body> 8</soapenv:Envelope>
Note that the "Request" element in the output above comes from the WSDL. If an element in args
contains no namespace prefix, the default namespace is assumed. Otherwise, you must add the namespace prefixes to the element names as necessary (e.g., ns1:name
).
Currently, when supplying JSON args, elements may not contain both child elements and a text value, even though that is allowed in the XML specification.
Example with XML String for the args
You may pass in a fully-formed XML string instead the individual elements in JSON args
and attributes that make up the XML. The XML string should not contain an XML declaration (e.g., <?xml version="1.0" encoding="UTF-8"?>
) or a document type declaration (e.g., <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">
).
var args = { _xml: "<ns1:MyRootElement xmlns:ns1="http://www.example.com/v1/ns1">
<ChildElement>elementvalue</ChildElement>
</ns1:MyRootElement>"
};
You must specify all of the namespaces and namespace prefixes yourself. The element(s) from the WSDL are not utilized as they were in the "Example with JSON as the args
" example above, which automatically populated the "Request" element.
Client.service.port.method(args, callback[, options[, extraHeaders]]) - call a method using a specific service and port
args
(Object): Arguments that generate an XML document inside of the SOAP Body section.callback
(Function)options
(Object): See Client.method(args, callback, options) - call method on the SOAP service. for a description.extraHeaders
(Object): Sets HTTP headers for the WSDL request.
Example
1 client.MyService.MyPort.MyFunction({name: 'value'}, function(err, result) { 2 // result is a javascript object 3 })
Options (optional)
- Accepts any option that the request module accepts, see here.
- For example, you could set a timeout of 5 seconds on the request like this:
1 client.MyService.MyPort.MyFunction({name: 'value'}, function(err, result) { 2 // result is a javascript object 3 }, {timeout: 5000})
- You can measure the elapsed time on the request by passing the time option:
1 client.MyService.MyPort.MyFunction({name: 'value'}, function(err, result) { 2 // client.lastElapsedTime - the elapsed time of the last request in milliseconds 3 }, {time: true})
1 client.MyService.MyPort.MyFunction({name: 'value'}, function(err, result) { 2 // client.lastElapsedTime - the elapsed time of the last request in milliseconds 3 }, { 4 proxy: { 5 protocol: 'https', 6 host: '127.0.0.1', 7 port: 9000, 8 auth: { 9 username: 'mikeymike', 10 password: 'rapunz3l' 11 } 12 } 13 })
- You can modify xml (string) before call:
1 client.MyService.MyPort.MyFunction({name: 'value'}, function(err, result) { 2 // client.lastElapsedTime - the elapsed time of the last request in milliseconds 3 }, {postProcess: function(_xml) { 4 return _xml.replace('text', 'newtext'); 5 }})
Extra Headers (optional)
Object properties define extra HTTP headers to be sent on the request.
- Add custom User-Agent:
1client.addHttpHeader('User-Agent', `CustomUserAgent`);
Alternative method call using callback-last pattern
To align method call signature with node' standard callback-last patter and event allow promisification of method calls, the following method signatures are also supported:
1client.MyService.MyPort.MyFunction({name: 'value'}, options, function (err, result) { 2 // result is a javascript object 3}) 4 5client.MyService.MyPort.MyFunction({name: 'value'}, options, extraHeaders, function (err, result) { 6 // result is a javascript object 7})
Overriding the namespace prefix
node-soap
is still working out some kinks regarding namespaces. If you find that an element is given the wrong namespace prefix in the request body, you can add the prefix to it's name in the containing object. I.E.:
1 client.MyService.MyPort.MyFunction({'ns1:name': 'value'}, function(err, result) { 2 // request body sent with `<ns1:name`, regardless of what the namespace should have been. 3 }, {timeout: 5000})
- Remove namespace prefix of param
1 client.MyService.MyPort.MyFunction({':name': 'value'}, function(err, result) { 2 // request body sent with `<name`, regardless of what the namespace should have been. 3 }, {timeout: 5000})
Client.lastRequest - the property that contains last full soap request for client logging
Client.setEndpoint(url) - overwrite the SOAP service endpoint address
Client Events
Client instances emit the following events:
request
Emitted before a request is sent. The event handler has the signature (xml, eid)
.
- xml - The entire Soap request (Envelope) including headers.
- eid - The exchange id.
message
Emitted before a request is sent, but only the body is passed to the event handler. Useful if you don't want to log /store Soap headers. The event handler has the signature (message, eid)
.
- message - Soap body contents.
- eid - The exchange id.
soapError
Emitted when an erroneous response is received. Useful if you want to globally log errors. The event handler has the signature (error, eid)
.
- error - An error object which also contains the resoponse.
- eid - The exchange id.
response
Emitted after a response is received. This is emitted for all responses (both success and errors). The event handler has the signature (body, response, eid)
- body - The SOAP response body.
- response - The entire
IncomingMessage
response object. - eid - The exchange id.
An 'exchange' is a request/response couple. Event handlers receive the exchange id in all events. The exchange id is the same for the requests events and the responses events, this way you can use it to retrieve the matching request when an response event is received.
By default exchange ids are generated by using node-uuid but you can use options in client calls to pass your own exchange id.
Example :
1 client.MyService.MyPort.MyFunction(args , function(err, result) { 2 3 }, {exchangeId: myExchangeId})
WSDL
A WSDL instance can also be instantiated directly when you want to (un)marshal messages without doing SOAP calls. This can be used when a WSDL does not contain bindings for services (e.g. some Windows Communication Foundation SOAP web services).
WSDL.constructor(wsdl, baseURL, options):
Construct a WSDL instance from either the WSDL content or the URL to the WSDL.
Parameters
- wsdl: A string wSDL or an URL to the WSDL
- baseURL: base URL for the SOAP API
- options: options (see source for details), use
{}
as default.
wsdl.xmlToObject(xml):
Unmarshal XML to object.
Parameters:
- xml: SOAP response (XML) to unmarshal
Returns:
Object containing the object types from the xml as keys.
wsdl.objectToXML(object, typeName, namespacePrefix, namespaceURI, ...):
Marshal an object to XML
Parameters:
- object: Object to marshal
- typeName: type (as per the wsdl) of the object
- namespacePrefix: namespace prefix
- namespaceURI: URI of the namespace
Returns:
XML representation of object.
Example:
1// Abstracted from a real use case 2import { AxiosInstance } from 'axios'; 3import { WSDL } from 'soap'; 4import { IProspectType } from './types'; 5 6// A WSDL in a string. 7const WSDL_CONTENT = "..."; 8 9const httpClient: AxiosInstance = /* ... instantiate ... */; 10const url = 'http://example.org/SoapService.svc'; 11 12const wsdl = new WSDL(WSDL_CONTENT, baseURL, {}); 13 14async function sampleGetCall(): IProspectType | undefined { 15 const res = await httpClient.get(`${baseURL}/GetProspect`); 16 17 const object = wsdl.xmlToObject(res.data); 18 19 if (!object.ProspectType) { 20 // Response did not contain the expected type 21 return undefined; 22 } 23 // Optionally, unwrap and set defaults for some fields 24 // Ensure that the object meets the expected prototype 25 // Finally cast and return the result. 26 return object.ProspectType as IProspectType; 27} 28 29async function samplePostCall(prospect: IProspectType) { 30 // objectToXML(object, typeName, namespacePrefix, namespaceURI, ...) 31 const objectBody = wsdl.objectToXML(obj, 'ProspectType', '', ''); 32 const data = `<?xml version="1.0" ?>${body}`; 33 34 const res = await httpClient.post(`${baseURL}/ProcessProspect`, data); 35 // Optionally, deserialize request and return response status. 36}
Security
node-soap
has several default security protocols. You can easily add your own
as well. The interface is quite simple. Each protocol defines these optional methods:
addOptions(options)
- a method that accepts an options arg that is eventually passed directly torequest
.addHeaders(headers)
- a method that accepts an argument with HTTP headers, to add new ones.toXML()
- a method that returns a string of XML to be appended to the SOAP headers. Not executed ifpostProcess
is also defined.postProcess(xml, envelopeKey)
- a method that receives the the assembled request XML plus envelope key, and returns a processed string of XML. Executed beforeoptions.postProcess
.
BasicAuthSecurity
1 client.setSecurity(new soap.BasicAuthSecurity('username', 'password'));
BearerSecurity
1 client.setSecurity(new soap.BearerSecurity('token'));
ClientSSLSecurity
Note: If you run into issues using this protocol, consider passing these options as default request options to the constructor:
rejectUnauthorized: false
strictSSL: false
secureOptions: constants.SSL_OP_NO_TLSv1_2
(this is likely needed for node >= 10.0)
If you want to reuse tls sessions, you can use the option forever: true
.
1client.setSecurity(new soap.ClientSSLSecurity( 2 '/path/to/key', 3 'path/to/cert', 4 '/path/to/ca-cert', /*or an array of buffer: [fs.readFileSync('/path/to/ca-cert/1', 'utf8'), 5 'fs.readFileSync('/path/to/ca-cert/2', 'utf8')], */ 6 { /*default request options like */ 7 // strictSSL: true, 8 // rejectUnauthorized: false, 9 // hostname: 'some-hostname' 10 // secureOptions: constants.SSL_OP_NO_TLSv1_2, 11 // forever: true, 12 }, 13 ));
ClientSSLSecurityPFX
Note: If you run into issues using this protocol, consider passing these options as default request options to the constructor:
rejectUnauthorized: false
strictSSL: false
secureOptions: constants.SSL_OP_NO_TLSv1_2
(this is likely needed for node >= 10.0)
If you want to reuse tls sessions, you can use the option forever: true
.
1client.setSecurity(new soap.ClientSSLSecurityPFX( 2 '/path/to/pfx/cert', // or a buffer: [fs.readFileSync('/path/to/pfx/cert', 'utf8'), 3 'path/to/optional/passphrase', 4 { /*default request options like */ 5 // strictSSL: true, 6 // rejectUnauthorized: false, 7 // hostname: 'some-hostname' 8 // secureOptions: constants.SSL_OP_NO_TLSv1_2, 9 // forever: true, 10 }, 11 ));
WSSecurity
WSSecurity
implements WS-Security. UsernameToken and PasswordText/PasswordDigest is supported.
1 var options = { 2 hasNonce: true, 3 actor: 'actor' 4 }; 5 var wsSecurity = new soap.WSSecurity('username', 'password', options) 6 client.setSecurity(wsSecurity);
the options
object is optional and can contain the following properties:
passwordType
: 'PasswordDigest' or 'PasswordText' (default:'PasswordText'
)hasTimeStamp
: adds Timestamp element (default:true
)hasTokenCreated
: adds Created element (default:true
)hasNonce
: adds Nonce element (default:false
)mustUnderstand
: adds mustUnderstand=1 attribute to security tag (default:false
)actor
: if set, adds Actor attribute with given value to security tag (default:''
)
WSSecurityCert
WS-Security X509 Certificate support.
1 var privateKey = fs.readFileSync(privateKeyPath); 2 var publicKey = fs.readFileSync(publicKeyPath); 3 var password = ''; // optional password 4 var options = { 5 hasTimeStamp: true, 6 additionalReferences: [ 7 'wsa:Action', 8 'wsa:ReplyTo', 9 'wsa:To', 10 ], 11 signerOptions: { 12 prefix: 'ds', 13 attrs: { Id: 'Signature' }, 14 existingPrefixes: { 15 wsse: 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd', 16 } 17 } 18 } 19 var wsSecurity = new soap.WSSecurityCert(privateKey, publicKey, password, options); 20 client.setSecurity(wsSecurity);
The options
object is optional and can contain the following properties:
hasTimeStamp
: Includes Timestamp tags (default:true
)signatureTransformations
: sets the Reference Transforms Algorithm (default ['http://www.w3.org/2000/09/xmldsig#enveloped-signature', 'http://www.w3.org/2001/10/xml-exc-c14n#']). Type is a string arraysignatureAlgorithm
: set tohttp://www.w3.org/2001/04/xmldsig-more#rsa-sha256
to use sha256additionalReferences
: (optional) Array of Soap headers that need to be signed. This need to be added usingclient.addSoapHeader('header')
signerOptions
: (optional) passes options to the XML Signer package - from (https://github.com/yaronn/xml-crypto)existingPrefixes
: (optional) A hash of prefixes and namespaces prefix: namespace that shouldn't be in the signature because they already exist in the xml (default:{ 'wsse': 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd' }
)prefix
: (optional) Adds this value as a prefix for the generated signature tags.attrs
: (optional) A hash of attributes and values attrName: value to add to the signature root nodeidMode
: (optional) either 'wssecurity' to generate wsse-scoped reference Id on or undefined for an unscoped reference Id
WSSecurityPlusCert
Use WSSecurity and WSSecurityCert together.
1 var wsSecurity = new soap.WSSecurity(/* see WSSecurity above */); 2 var wsSecurityCert = new soap.WSSecurityCert(/* see WSSecurityCert above */); 3 var wsSecurityPlusCert = new soap.WSSecurityPlusCert(wsSecurity, wsSecurityCert); 4 client.setSecurity(wsSecurityPlusCert);
Option examples
hasTimeStamp:true
1<soap:Header> 2 <wsse:Security soap:mustUnderstand="1"> 3 <wsse:BinarySecurityToken>XXX</wsse:BinarySecurityToken> 4 <!-- The Timestamp group of tags are added and signed --> 5 <Timestamp xmlns="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" Id="Timestamp"> 6 <Created>2019-10-01T08:17:50Z</Created> 7 <Expires>2019-10-01T08:27:50Z</Expires> 8 </Timestamp> 9 <Signature xmlns="http://www.w3.org/2000/09/xmldsig#"> 10 <SignedInfo> 11 ... 12 <Reference URI="#Timestamp"> 13 <Transforms> 14 <Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature"/> 15 <Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"/> 16 </Transforms> 17 <DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"/> 18 <DigestValue>XyZ=</DigestValue> 19 </Reference> 20 </SignedInfo> 21 </Signature> 22 </wsse:Security> 23</soap:Header>
additionalReferences: ['To']
1<soap:Header> 2 <To Id="To">localhost.com</To> 3 <wsse:Security soap:mustUnderstand="1"> 4 <wsse:BinarySecurityToken>XXX</wsse:BinarySecurityToken> 5 <Signature xmlns="http://www.w3.org/2000/09/xmldsig#"> 6 <SignedInfo> 7 <CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"/> 8 <SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1"/> 9 <!-- The "To" tag is signed and added as a reference --> 10 <Reference URI="#To"> 11 <Transforms> 12 <Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature"/> 13 <Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"/> 14 </Transforms> 15 <DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"/> 16 <DigestValue>XYZ</DigestValue> 17 </Reference> 18 </SignedInfo> 19 <SignatureValue> 20 Rf6M4F4puQuQHJIPtJz1CZIVvF3qOdpEEcuAiooWkX5ecnAHSf3RW3sOIzFUWW7VOOncJcts/3xr8DuN4+8Wm9hx1MoOcWJ6kyRIdVNbQWLseIcAhxYCntRY57T2TBXzpb0UPA56pry1+TEcnIQXhdIzG5YT+tTVTp+SZHHcnlP5Y+yqnIOH9wzgRvAovbydTYPCODF7Ana9K/7CSGDe7vpVT85CUYUcJE4DfTxaRa9gKkKrBdPN9vFVi0WfxtMF4kv23cZRCZzS5+CoLfPlx3mq65gVXsqH01RLbktNJq9VaQKcZUgapmUCMzrYhqyzUQJ8HrSHqe+ya2GsjlB0VQ== 21 </SignatureValue> 22 <KeyInfo> 23 <wsse:SecurityTokenReference 24 xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"> 25 <wsse:Reference URI="#x509-c5c0d213676f4a6ba5e6fa58074eb57a" 26 ValueType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509v3"/> 27 </wsse:SecurityTokenReference> 28 </KeyInfo> 29 </Signature> 30 </wsse:Security> 31</soap:Header>
signerOptions.prefix:'ds'
1<soap:Header> 2 <To Id="To">localhost.com</To> 3 <wsse:Security soap:mustUnderstand="1"> 4 <wsse:BinarySecurityToken>XXX</wsse:BinarySecurityToken> 5 <!-- Signature and children tags are given the prefix defined. --> 6 <ds:Signature xmlns="http://www.w3.org/2000/09/xmldsig#"> 7 <ds:SignedInfo> 8 <ds:CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"/> 9 <ds:SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1"/> 10 <ds:Reference URI="#To"> 11 <ds:Transforms> 12 <ds:Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature"/> 13 <ds:Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"/> 14 </ds:Transforms> 15 <ds:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"/> 16 <ds:DigestValue>XYZ</DigestValue> 17 </ds:Reference> 18 </ds:SignedInfo> 19 <ds:SignatureValue> 20 Rf6M4F4puQuQHJIPtJz1CZIVvF3qOdpEEcuAiooWkX5ecnAHSf3RW3sOIzFUWW7VOOncJcts/3xr8DuN4+8Wm9hx1MoOcWJ6kyRIdVNbQWLseIcAhxYCntRY57T2TBXzpb0UPA56pry1+TEcnIQXhdIzG5YT+tTVTp+SZHHcnlP5Y+yqnIOH9wzgRvAovbydTYPCODF7Ana9K/7CSGDe7vpVT85CUYUcJE4DfTxaRa9gKkKrBdPN9vFVi0WfxtMF4kv23cZRCZzS5+CoLfPlx3mq65gVXsqH01RLbktNJq9VaQKcZUgapmUCMzrYhqyzUQJ8HrSHqe+ya2GsjlB0VQ== 21 </ds:SignatureValue> 22 <ds:KeyInfo> 23 <wsse:SecurityTokenReference 24 xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"> 25 <wsse:Reference URI="#x509-c5c0d213676f4a6ba5e6fa58074eb57a" 26 ValueType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509v3"/> 27 </wsse:SecurityTokenReference> 28 </ds:KeyInfo> 29 </ds:Signature> 30 </wsse:Security> 31</soap:Header>
signerOptions.attrs:{ Id: 'signature-100', foo:'bar'}
1<soap:Header> 2 <wsse:Security soap:mustUnderstand="1"> 3 <wsse:BinarySecurityToken>XXX</wsse:BinarySecurityToken> 4 <!-- The Timestamp group of tags are added and signed --> 5 <Timestamp xmlns="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" Id="Timestamp"> 6 <Created>2019-10-01T08:17:50Z</Created> 7 <Expires>2019-10-01T08:27:50Z</Expires> 8 </Timestamp> 9 <Signature Id="signature-100" foo="bar" xmlns="http://www.w3.org/2000/09/xmldsig#"> 10 <SignedInfo> 11 ... 12 <Reference URI="#Timestamp"> 13 <Transforms> 14 <Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature"/> 15 <Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"/> 16 </Transforms> 17 <DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"/> 18 <DigestValue>XyZ=</DigestValue> 19 </Reference> 20 </SignedInfo> 21 </Signature> 22 </wsse:Security> 23</soap:Header>
WSSecurityCertWithToken
WS-Security X509 Certificate support. Just like WSSecurityCert, except that it accepts the input properties as a single object, with two properties added username
 and password
. Which if added, will add a UsernameToken Element to the xml security element.
1<wsse:UsernameToken> 2 <wsse:Username>someusername</wsse:Username> 3 <wsse:Password>someusername's password</wsse:Password> 4</wsse:UsernameToken>
NTLMSecurity
Parameter invocation:
1 client.setSecurity(new soap.NTLMSecurity('username', 'password', 'domain', 'workstation'));
This can also be set up with a JSON object, substituting values as appropriate, for example:
1 var loginData = {username: 'username', password: 'password', domain: 'domain', workstation: 'workstation'}; 2 client.setSecurity(new soap.NTLMSecurity(loginData));
Handling XML Attributes, Value and XML (wsdlOptions).
Sometimes it is necessary to override the default behaviour of node-soap
in order to deal with the special requirements
of your code base or a third library you use. Therefore you can use the wsdlOptions
Object, which is passed in the
#createClient()
method and could have any (or all) of the following contents:
1var wsdlOptions = { 2 attributesKey: 'theAttrs', 3 valueKey: 'theVal', 4 xmlKey: 'theXml' 5}
If nothing (or an empty Object {}
) is passed to the #createClient()
method, the node-soap
defaults (attributesKey: 'attributes'
, valueKey: '$value'
and xmlKey: '$xml'
) are used.
Overriding the value
key
By default, node-soap
uses $value
as the key for any parsed XML value which may interfere with your other code as it
could be some reserved word, or the $
in general cannot be used for a key to start with.
You can define your own valueKey
by passing it in the wsdl_options
to the createClient call:
1var wsdlOptions = { 2 valueKey: 'theVal' 3}; 4 5soap.createClient(__dirname + '/wsdl/default_namespace.wsdl', wsdlOptions, function (err, client) { 6 // your code 7});
Overriding the xml
key
By default, node-soap
uses $xml
as the key to pass through an XML string as is; without parsing or namespacing it. It overrides all the other content that the node might have otherwise had.
For example :
1{ 2 dom: { 3 nodeone: { 4 $xml: '<parentnode type="type"><childnode></childnode></parentnode>', 5 siblingnode: 'Cant see me.' 6 }, 7 nodetwo: { 8 parentnode: { 9 attributes: { 10 type: 'type' 11 }, 12 childnode: '' 13 } 14 } 15 } 16};
could become
1<tns:dom> 2 <tns:nodeone> 3 <parentnode type="type"> 4 <childnode></childnode> 5 </parentnode> 6 </tns:nodeone> 7 <tns:nodetwo> 8 <tns:parentnode type="type"> 9 <tns:childnode></tns:childnode> 10 </tns:parent> 11 </tns:nodetwo> 12</tns:dom>
You can define your own xmlKey
by passing it in the wsdl_options
object to the createClient call:
1var wsdlOptions = { 2 xmlKey: 'theXml' 3}; 4 5soap.createClient(__dirname + '/wsdl/default_namespace.wsdl', wsdlOptions, function (err, client) { 6 // your code 7});
Overriding the attributes
key
By default, node-soap
uses attributes
as the key to define a nodes attributes.
1{ 2 parentnode: { 3 childnode: { 4 attributes: { 5 name: 'childsname' 6 }, 7 $value: 'Value' 8 } 9 } 10}
could become
1<parentnode> 2 <childnode name="childsname">Value</childnode> 3</parentnode>
However, attributes
may be a reserved key for some systems that actually want a node called attributes
1<attributes> 2</attributes>
You can define your own attributesKey
by passing it in the wsdl_options
object to the createClient call:
1var wsdlOptions = { 2 attributesKey: '$attributes' 3}; 4 5soap.createClient(__dirname + '/wsdl/default_namespace.wsdl', wsdlOptions, function (err, client) { 6 client.method({ 7 parentnode: { 8 childnode: { 9 $attributes: { 10 name: 'childsname' 11 }, 12 $value: 'Value' 13 } 14 } 15 }); 16});
Overriding imports relative paths
By default, WSDL and schema files import other schemas and types using relative paths.
However in some systems (i.e. NetSuite) when the wsdl is downloaded for offline caching, all files are flattened under a single directory and all the imports fail.
Passing this option allows node-soap
to correctly load all files.
1var options ={ 2 wsdl_options = { fixedPath: true } 3}; 4soap.createClient(__dirname+'/wsdl/fixedPath/netsuite.wsdl', options, function(err, client) { 5 // your code 6});
Overriding import locations
You can override the URIs or paths of imports in the WSDL by specifying a overrideImportLocation
function in the WSDL options.
1const options ={ 2 wsdl_options = { 3 overrideImportLocation: (location) => { 4 return 'https://127.0.0.1/imported-service.wsdl'; 5 } 6 } 7}; 8soap.createClient('https://127.0.0.1/service.wsdl', options, function(err, client) { 9 // your code 10});
Specifying the exact namespace definition of the root element
In rare cases, you may want to precisely control the namespace definition that is included in the root element.
You can specify the namespace definitions by setting the overrideRootElement
key in the wsdlOptions
like so:
1var wsdlOptions = { 2 overrideRootElement: { 3 namespace: 'xmlns:tns', 4 xmlnsAttributes: [{ 5 name: 'xmlns:ns2', 6 value: "http://tempuri.org/" 7 }, { 8 name: 'xmlns:ns3', 9 value: "http://sillypets.com/xsd" 10 }] 11 } 12};
To see it in practice, have a look at the sample files in: test/request-response-samples/addPets__force_namespaces
Custom Deserializer
Sometimes it's useful to handle deserialization in your code instead of letting node-soap do it. For example if the soap response contains dates that are not in a format recognized by javascript, you might want to use your own function to handle them.
To do so, you can pass a customDeserializer
object in options
. The properties of this object are the types that your deserializer handles itself.
Example :
1 2 var wsdlOptions = { 3 customDeserializer: { 4 5 // this function will be used to any date found in soap responses 6 date: function (text, context) { 7 /* text is the value of the xml element. 8 context contains the name of the xml element and other infos : 9 { 10 name: 'lastUpdatedDate', 11 object: {}, 12 schema: 'xsd:date', 13 id: undefined, 14 nil: false 15 } 16 17 */ 18 return text; 19 } 20 } 21 }; 22 23 soap.createClient(__dirname + '/wsdl/default_namespace.wsdl', wsdlOptions, function (err, client) { 24 ... 25 }); 26
Changing the tag formats to use self-closing (empty element) tags
The XML specification specifies that there is no semantic difference between <Tag></Tag>
and <Tag />
, and node-soap defaults to using the <Tag></Tag>
format. But if your web service is particular, or if there is a stylistic preference, the useEmptyTag
option causes tags with no contents to use the <Tag />
format instead.
1var wsdlOptions = { 2 useEmptyTag: true 3};
For example: { MyTag: { attributes: { MyAttr: 'value' } } }
is:
- Without useEmptyTag:
<MyTag MyAttr="value"></MyTag>
- With useEmptyTag set to true:
<MyTag MyAttr="value" />
Handling "ignored" namespaces
If an Element in a schema
definition depends on an Element which is present in the same namespace, normally the tns:
namespace prefix is used to identify this Element. This is not much of a problem as long as you have just one schema
defined
(inline or in a separate file). If there are more schema
files, the tns:
in the generated soap
file resolved mostly to the parent wsdl
file,
which was obviously wrong.
node-soap
now handles namespace prefixes which shouldn't be resolved (because it's not necessary) as so called ignoredNamespaces
which default to an Array of 3 Strings (['tns', 'targetNamespace', 'typedNamespace']
).
If this is not sufficient for your purpose you can easily add more namespace prefixes to this Array, or override it in its entirety
by passing an ignoredNamespaces
object within the options
you pass in soap.createClient()
method.
A simple ignoredNamespaces
object, which only adds certain namespaces could look like this:
var options = {
ignoredNamespaces: {
namespaces: ['namespaceToIgnore', 'someOtherNamespace']
}
}
This would extend the ignoredNamespaces
of the WSDL
processor to ['tns', 'targetNamespace', 'typedNamespace', 'namespaceToIgnore', 'someOtherNamespace']
.
If you want to override the default ignored namespaces you would simply pass the following ignoredNamespaces
object within the options
:
var options = {
ignoredNamespaces: {
namespaces: ['namespaceToIgnore', 'someOtherNamespace'],
override: true
}
}
This would override the default ignoredNamespaces
of the WSDL
processor to ['namespaceToIgnore', 'someOtherNamespace']
. (This shouldn't be necessary, anyways).
Handling "ignoreBaseNameSpaces" attribute
If an Element in a schema
definition depends has a basenamespace defined but the request does not need that value, for example you have a "sentJob" with basenamespace "v20"
but the request need only:
By default the attribute is set to true. An example to use:
A simple ignoredNamespaces
object, which only adds certain namespaces could look like this:
var options = {
ignoredNamespaces: true
}
soap-stub
Unit testing services that use soap clients can be very cumbersome. In order to get
around this you can use soap-stub
in conjunction with sinon
to stub soap with
your clients.
Example
1// test-initialization-script.js 2var sinon = require('sinon'); 3var soapStub = require('soap/soap-stub'); 4 5var urlMyApplicationWillUseWithCreateClient = 'http://path-to-my-wsdl'; 6var clientStub = { 7 SomeOperation: sinon.stub() 8}; 9 10clientStub.SomeOperation.respondWithError = soapStub.createErroringStub({..error json...}); 11clientStub.SomeOperation.respondWithSuccess = soapStub.createRespondingStub({..success json...}); 12 13soapStub.registerClient('my client alias', urlMyApplicationWillUseWithCreateClient, clientStub); 14 15// test.js 16var soapStub = require('soap/soap-stub'); 17 18describe('myService', function() { 19 var clientStub; 20 var myService; 21 22 beforeEach(function() { 23 clientStub = soapStub.getStub('my client alias'); 24 soapStub.reset(); 25 myService.init(clientStub); 26 }); 27 28 describe('failures', function() { 29 beforeEach(function() { 30 clientStub.SomeOperation.respondWithError(); 31 }); 32 33 it('should handle error responses', function() { 34 myService.somethingThatCallsSomeOperation(function(err, response) { 35 // handle the error response. 36 }); 37 }); 38 }); 39});
Contributors
- Author: Vinay Pulim
- Active maintainers:
- Previous maintainers (not active for a long time):
- All Contributors
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
13 commit(s) and 4 issue activity found in the last 90 days -- score normalized to 10
Reason
no binaries found in the repo
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: MIT License: LICENSE:0
Reason
0 existing vulnerabilities detected
Reason
Found 12/30 approved changesets -- score normalized to 4
Reason
security policy file detected
Details
- Info: security policy file detected: SECURITY.md:1
- Warn: no linked content found
- Warn: One or no descriptive hints of disclosure, vulnerability, and/or timelines in security policy
- Info: Found text in security policy: SECURITY.md:1
Reason
dependency not pinned by hash detected -- score normalized to 3
Details
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/pr.yml:7: update your workflow using https://app.stepsecurity.io/secureworkflow/vpulim/node-soap/pr.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/pr.yml:8: update your workflow using https://app.stepsecurity.io/secureworkflow/vpulim/node-soap/pr.yml/master?enable=pin
- Info: 0 out of 2 GitHub-owned GitHubAction dependencies pinned
- Info: 1 out of 1 npmCommand dependencies pinned
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
detected GitHub workflow tokens with excessive permissions
Details
- Warn: no topLevel permission defined: .github/workflows/pr.yml:1
- Info: no jobLevel write permissions found
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 18 are checked with a SAST tool
Score
5.1
/10
Last Scanned on 2024-12-16
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More