soap 1.2.1 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Readme.md +551 -649
- package/lib/client.js +5 -2
- package/lib/client.js.map +1 -1
- package/lib/server.js +1 -1
- package/lib/server.js.map +1 -1
- package/lib/types.d.ts +1 -0
- package/lib/wsdl/elements.js +6 -0
- package/lib/wsdl/elements.js.map +1 -1
- package/lib/wsdl/index.js +58 -35
- package/lib/wsdl/index.js.map +1 -1
- package/package.json +9 -9
package/Readme.md
CHANGED
|
@@ -4,20 +4,20 @@
|
|
|
4
4
|
|
|
5
5
|
# SOAP client and server for node.js.
|
|
6
6
|
|
|
7
|
-
This module lets you connect to web services using SOAP.
|
|
7
|
+
This module lets you connect to web services using SOAP. It also provides a server that allows you to run your own SOAP services.
|
|
8
8
|
|
|
9
9
|
<!-- Run `npm run toc` to update below section -->
|
|
10
10
|
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
|
|
11
11
|
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
|
|
12
12
|
|
|
13
|
-
- [Features
|
|
13
|
+
- [Features](#features)
|
|
14
14
|
- [Install](#install)
|
|
15
15
|
- [Support](#support)
|
|
16
16
|
- [Module](#module)
|
|
17
17
|
- [soap.createClient(url[, options], callback) - create a new SOAP client from a WSDL url. Also supports a local filesystem path.](#soapcreateclienturl-options-callback---create-a-new-soap-client-from-a-wsdl-url-also-supports-a-local-filesystem-path)
|
|
18
18
|
- [soap.createClientAsync(url[, options]) - create a new SOAP client from a WSDL url. Also supports a local filesystem path.](#soapcreateclientasyncurl-options---create-a-new-soap-client-from-a-wsdl-url-also-supports-a-local-filesystem-path)
|
|
19
|
-
- [soap.listen(
|
|
20
|
-
- [soap.listen(
|
|
19
|
+
- [soap.listen(*server*, *path*, *services*, *wsdl*, *callback*) - create a new SOAP server that listens on *path* and provides *services*.](#soaplistenserver-path-services-wsdl-callback---create-a-new-soap-server-that-listens-on-path-and-provides-services)
|
|
20
|
+
- [soap.listen(*server*, *options*) - create a new SOAP server that listens on *path* and provides *services*.](#soaplistenserver-options---create-a-new-soap-server-that-listens-on-path-and-provides-services)
|
|
21
21
|
- [Server Logging](#server-logging)
|
|
22
22
|
- [Server Events](#server-events)
|
|
23
23
|
- [Server Response on one-way calls](#server-response-on-one-way-calls)
|
|
@@ -30,11 +30,11 @@ This module lets you connect to web services using SOAP. It also provides a serv
|
|
|
30
30
|
- [Client](#client)
|
|
31
31
|
- [Client.describe() - description of services, ports and methods as a JavaScript object](#clientdescribe---description-of-services-ports-and-methods-as-a-javascript-object)
|
|
32
32
|
- [Client.setSecurity(security) - use the specified security protocol](#clientsetsecuritysecurity---use-the-specified-security-protocol)
|
|
33
|
-
- [Client
|
|
34
|
-
- [Client.*method*Async(args, options) - call
|
|
35
|
-
- [Client
|
|
33
|
+
- [Client.*method*(args, callback, options) - call *method* on the SOAP service.](#clientmethodargs-callback-options---call-method-on-the-soap-service)
|
|
34
|
+
- [Client.*method*Async(args, options) - call *method* on the SOAP service.](#clientmethodasyncargs-options---call-method-on-the-soap-service)
|
|
35
|
+
- [Client.*service*.*port*.*method*(args, callback[, options[, extraHeaders]]) - call a *method* using a specific *service* and *port*](#clientserviceportmethodargs-callback-options-extraheaders---call-a-method-using-a-specific-service-and-port)
|
|
36
36
|
- [Overriding the namespace prefix](#overriding-the-namespace-prefix)
|
|
37
|
-
- [Client
|
|
37
|
+
- [Client.*lastRequest* - the property that contains last full soap request for client logging](#clientlastrequest---the-property-that-contains-last-full-soap-request-for-client-logging)
|
|
38
38
|
- [Client.setEndpoint(url) - overwrite the SOAP service endpoint address](#clientsetendpointurl---overwrite-the-soap-service-endpoint-address)
|
|
39
39
|
- [Client Events](#client-events)
|
|
40
40
|
- [_request_](#_request_)
|
|
@@ -62,6 +62,7 @@ This module lets you connect to web services using SOAP. It also provides a serv
|
|
|
62
62
|
- [Overriding imports relative paths](#overriding-imports-relative-paths)
|
|
63
63
|
- [Overriding import locations](#overriding-import-locations)
|
|
64
64
|
- [Specifying the exact namespace definition of the root element](#specifying-the-exact-namespace-definition-of-the-root-element)
|
|
65
|
+
- [Overriding element key specification in XML](#overriding-element-key-specification-in-xml)
|
|
65
66
|
- [Custom Deserializer](#custom-deserializer)
|
|
66
67
|
- [Changing the tag formats to use self-closing (empty element) tags](#changing-the-tag-formats-to-use-self-closing-empty-element-tags)
|
|
67
68
|
- [Handling "ignored" namespaces](#handling-ignored-namespaces)
|
|
@@ -72,14 +73,14 @@ This module lets you connect to web services using SOAP. It also provides a serv
|
|
|
72
73
|
|
|
73
74
|
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
|
|
74
75
|
|
|
75
|
-
## Features
|
|
76
|
+
## Features
|
|
76
77
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
78
|
+
* Very simple API
|
|
79
|
+
* Handles both RPC and Document schema types
|
|
80
|
+
* Supports multiRef SOAP messages (thanks to [@kaven276](https://github.com/kaven276))
|
|
81
|
+
* Support for both synchronous and asynchronous method handlers
|
|
82
|
+
* WS-Security UsernameToken Profile 1.0
|
|
83
|
+
* Supports [Express](http://expressjs.com/) based web server (body parser middleware can be used)
|
|
83
84
|
|
|
84
85
|
## Install
|
|
85
86
|
|
|
@@ -96,54 +97,52 @@ Paid support can be provided as well, please contact one of the active maintaine
|
|
|
96
97
|
|
|
97
98
|
### soap.createClient(url[, options], callback) - create a new SOAP client from a WSDL url. Also supports a local filesystem path.
|
|
98
99
|
|
|
99
|
-
- `url` (
|
|
100
|
-
- `options` (
|
|
101
|
-
- `endpoint` (
|
|
102
|
-
- `envelopeKey` (
|
|
103
|
-
- `preserveWhitespace` (
|
|
104
|
-
- `escapeXML` (
|
|
105
|
-
- `suppressStack` (
|
|
106
|
-
- `returnFault` (
|
|
107
|
-
- `forceSoap12Headers` (
|
|
108
|
-
- `httpClient` (
|
|
109
|
-
- `request` (
|
|
110
|
-
- `wsdl_headers` (
|
|
111
|
-
- `wsdl_options` (
|
|
112
|
-
- `disableCache` (
|
|
113
|
-
- `wsdlCache` (
|
|
114
|
-
- `overridePromiseSuffix` (
|
|
115
|
-
- `normalizeNames` (
|
|
116
|
-
- `namespaceArrayElements` (
|
|
117
|
-
- `stream` (
|
|
118
|
-
- `returnSaxStream` (
|
|
119
|
-
- `parseReponseAttachments` (
|
|
100
|
+
- `url` (*string*): A HTTP/HTTPS URL, XML or a local filesystem path.
|
|
101
|
+
- `options` (*Object*):
|
|
102
|
+
- `endpoint` (*string*): Override the host specified by the SOAP service in the WSDL file.
|
|
103
|
+
- `envelopeKey` (*string*): Set a custom envelope key. (**Default:** `'soap'`)
|
|
104
|
+
- `preserveWhitespace` (*boolean*): Preserve any leading and trailing whitespace characters in text and cdata.
|
|
105
|
+
- `escapeXML` (*boolean*): Escape special XML characters (e.g. `&`, `>`, `<` etc) in SOAP messages. (**Default:** `true`)
|
|
106
|
+
- `suppressStack` (*boolean*): Suppress the full stack trace for error messages.
|
|
107
|
+
- `returnFault` (*boolean*): Return an `Invalid XML` SOAP fault upon a bad request. (**Default:** `false`)
|
|
108
|
+
- `forceSoap12Headers` (*boolean*): Enable SOAP 1.2 compliance.
|
|
109
|
+
- `httpClient` (*Object*): Override the built-in HttpClient object with your own. Must implement `request(rurl, data, callback, exheaders, exoptions)`.
|
|
110
|
+
- `request` (*Object*): Override the default request module ([Axios](https://axios-http.com/) as of `v0.40.0`).
|
|
111
|
+
- `wsdl_headers` (*Object*): Set HTTP headers with values to be sent on WSDL requests.
|
|
112
|
+
- `wsdl_options` (*Object*): Set options for the request module on WSDL requests. If using the default request module, see [Request Config | Axios Docs](https://axios-http.com/docs/req_config).
|
|
113
|
+
- `disableCache` (*boolean*): Prevents caching WSDL files and option objects.
|
|
114
|
+
- `wsdlCache` (*IWSDLCache*): Custom cache implementation. If not provided, defaults to caching WSDLs indefinitely.
|
|
115
|
+
- `overridePromiseSuffix` (*string*): Override the default method name suffix of WSDL operations for Promise-based methods. If any WSDL operation name ends with `Async', you must use this option. (**Default:** `Async`)
|
|
116
|
+
- `normalizeNames` (*boolean*): Replace non-identifier characters (`[^a-z$_0-9]`) with `_` in WSDL operation names. Note: Clients using WSDLs with two operations like `soap:method` and `soap-method` will be overwritten. In this case, you must use bracket notation instead (`client['soap:method']()`).
|
|
117
|
+
- `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>`. If `false`, it would be marshalled into `<list> <elem>1</elem> <elem>2</elem> </list>`. (**Default:** `true`)
|
|
118
|
+
- `stream` (*boolean*): Use streams to parse the XML SOAP responses. (**Default:** `false`)
|
|
119
|
+
- `returnSaxStream` (*boolean*): Return the SAX stream, transferring responsibility of parsing XML to the end user. Only valid when the *stream* option is set to `true`. (**Default:** `false`)
|
|
120
|
+
- `parseReponseAttachments` (*boolean*): Treat response as multipart/related response with MTOM attachment. Reach attachments on the `lastResponseAttachments` property of SoapClient. (**Default:** `false`)
|
|
120
121
|
- `encoding` (_string_): response data enconding, used with `parseReponseAttachments`. (**Default:** `utf8`)
|
|
121
|
-
- `callback` (
|
|
122
|
-
- `err` (
|
|
123
|
-
- `result` (
|
|
122
|
+
- `callback` (*Function*):
|
|
123
|
+
- `err` (*Error* | *<AggregateError>*)
|
|
124
|
+
- `result` (*Any*)
|
|
124
125
|
- Returns: `Client`
|
|
125
126
|
|
|
126
127
|
#### Example
|
|
127
128
|
|
|
128
129
|
HTTP/HTTPS:
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
var
|
|
132
|
-
var
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
130
|
+
``` javascript
|
|
131
|
+
var soap = require('soap');
|
|
132
|
+
var url = 'http://example.com/wsdl?wsdl';
|
|
133
|
+
var args = {name: 'value'};
|
|
134
|
+
|
|
135
|
+
soap.createClient(url, {}, function(err, client) {
|
|
136
|
+
client.MyFunction(args, function(err, result) {
|
|
137
|
+
console.log(result);
|
|
138
|
+
});
|
|
138
139
|
});
|
|
139
|
-
});
|
|
140
140
|
```
|
|
141
141
|
|
|
142
142
|
XML string format:
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
var
|
|
146
|
-
var xml = `
|
|
143
|
+
``` javascript
|
|
144
|
+
var soap = require('soap');
|
|
145
|
+
var xml = `
|
|
147
146
|
<?xml version="1.0" encoding="UTF-8"?>
|
|
148
147
|
<definitions xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/">
|
|
149
148
|
<message name="MyFunctionRequest"/>
|
|
@@ -172,182 +171,169 @@ var xml = `
|
|
|
172
171
|
</service>
|
|
173
172
|
</definitions>
|
|
174
173
|
`;
|
|
175
|
-
var args = {
|
|
174
|
+
var args = {name: 'value'};
|
|
176
175
|
|
|
177
|
-
soap.createClient(xml, {}, function
|
|
178
|
-
|
|
179
|
-
|
|
176
|
+
soap.createClient(xml, {}, function(err, client) {
|
|
177
|
+
client.MyFunction(args, function(err, result) {
|
|
178
|
+
console.log(result);
|
|
179
|
+
});
|
|
180
180
|
});
|
|
181
|
-
});
|
|
182
181
|
```
|
|
183
182
|
|
|
183
|
+
|
|
184
184
|
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.
|
|
185
185
|
|
|
186
186
|
### soap.createClientAsync(url[, options]) - create a new SOAP client from a WSDL url. Also supports a local filesystem path.
|
|
187
187
|
|
|
188
188
|
Construct a `Promise<Client>` with the given WSDL file.
|
|
189
189
|
|
|
190
|
-
- `url` (
|
|
191
|
-
- `options` (
|
|
190
|
+
- `url` (*string*): A HTTP/HTTPS URL, XML or a local filesystem path.
|
|
191
|
+
- `options` (*Object*): See [soap.createClient(url[, options], callback)](#soapcreateclienturl-options-callback---create-a-new-soap-client-from-a-wsdl-url-also-supports-a-local-filesystem-path) for a description.
|
|
192
192
|
- Returns: `Promise<Client>`
|
|
193
193
|
|
|
194
194
|
#### Example
|
|
195
195
|
|
|
196
|
-
```javascript
|
|
197
|
-
var soap = require(
|
|
198
|
-
var url =
|
|
199
|
-
var args = {
|
|
200
|
-
|
|
201
|
-
// then/catch
|
|
202
|
-
soap
|
|
203
|
-
.createClientAsync(url)
|
|
204
|
-
.then((client) => {
|
|
196
|
+
``` javascript
|
|
197
|
+
var soap = require('soap');
|
|
198
|
+
var url = 'http://example.com/wsdl?wsdl';
|
|
199
|
+
var args = {name: 'value'};
|
|
200
|
+
|
|
201
|
+
// then/catch
|
|
202
|
+
soap.createClientAsync(url).then((client) => {
|
|
205
203
|
return client.MyFunctionAsync(args);
|
|
206
|
-
})
|
|
207
|
-
.then((result) => {
|
|
204
|
+
}).then((result) => {
|
|
208
205
|
console.log(result);
|
|
209
206
|
});
|
|
210
207
|
|
|
211
|
-
// async/await
|
|
212
|
-
var client = await soap.createClientAsync(url);
|
|
213
|
-
var result = await client.MyFunctionAsync(args);
|
|
214
|
-
console.log(result[0]);
|
|
208
|
+
// async/await
|
|
209
|
+
var client = await soap.createClientAsync(url);
|
|
210
|
+
var result = await client.MyFunctionAsync(args);
|
|
211
|
+
console.log(result[0]);
|
|
215
212
|
```
|
|
216
213
|
|
|
217
214
|
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.
|
|
218
215
|
|
|
219
|
-
### soap.listen(
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
- `
|
|
224
|
-
- `
|
|
225
|
-
- `
|
|
226
|
-
- `
|
|
227
|
-
- `
|
|
228
|
-
- `
|
|
229
|
-
- `
|
|
230
|
-
- `
|
|
231
|
-
- `
|
|
232
|
-
- `
|
|
233
|
-
- `
|
|
234
|
-
- `
|
|
235
|
-
- `
|
|
236
|
-
- `
|
|
237
|
-
|
|
238
|
-
- `
|
|
239
|
-
- `
|
|
240
|
-
- `callback` (_Function_): A function to run after the server has been initialized.
|
|
216
|
+
### soap.listen(*server*, *path*, *services*, *wsdl*, *callback*) - create a new SOAP server that listens on *path* and provides *services*.
|
|
217
|
+
### soap.listen(*server*, *options*) - create a new SOAP server that listens on *path* and provides *services*.
|
|
218
|
+
|
|
219
|
+
- `server` (*Object*): A [http](https://nodejs.org/api/http.html) server or [Express](http://expressjs.com/) framework based server.
|
|
220
|
+
- `path` (*string*)
|
|
221
|
+
- `options` (*Object*): An object containing *server options* and [WSDL Options](#handling-xml-attributes-value-and-xml-wsdloptions)
|
|
222
|
+
- `path` (*string*)
|
|
223
|
+
- `services` (*Object*)
|
|
224
|
+
- `xml` (*string*)
|
|
225
|
+
- `uri` (*string*)
|
|
226
|
+
- `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.)
|
|
227
|
+
- `key` (*string* | *Buffer*): The private key of the server in PEM format. (Could be an array of keys). (Required)
|
|
228
|
+
- `passphrase` (*string*): The passphrase for the private key or pfx.
|
|
229
|
+
- `cert` (*string* | *Buffer*): The certificate key of the server in PEM format. (Could be an array of certs). (Required)
|
|
230
|
+
- `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.
|
|
231
|
+
- `crl` (*string* | *string[]*: PEM encoded CRLs (Certificate Revocation List)
|
|
232
|
+
- `ciphers` (*string*): A description of the ciphers to use or exclude, separated by `:`. The default cipher suite is:
|
|
233
|
+
- `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`)
|
|
234
|
+
- `services` (*Object*)
|
|
235
|
+
- `wsdl` (*string*): An XML string that defines the service.
|
|
236
|
+
- `callback` (*Function*): A function to run after the server has been initialized.
|
|
241
237
|
- Returns: `Server`
|
|
242
238
|
|
|
243
239
|
#### Example
|
|
244
240
|
|
|
245
|
-
```javascript
|
|
246
|
-
var myService = {
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
},
|
|
291
|
-
},
|
|
292
|
-
};
|
|
241
|
+
``` javascript
|
|
242
|
+
var myService = {
|
|
243
|
+
MyService: {
|
|
244
|
+
MyPort: {
|
|
245
|
+
MyFunction: function(args) {
|
|
246
|
+
return {
|
|
247
|
+
name: args.name
|
|
248
|
+
};
|
|
249
|
+
},
|
|
250
|
+
|
|
251
|
+
// This is how to define an asynchronous function with a callback.
|
|
252
|
+
MyAsyncFunction: function(args, callback) {
|
|
253
|
+
// do some work
|
|
254
|
+
callback({
|
|
255
|
+
name: args.name
|
|
256
|
+
});
|
|
257
|
+
},
|
|
258
|
+
|
|
259
|
+
// This is how to define an asynchronous function with a Promise.
|
|
260
|
+
MyPromiseFunction: function(args) {
|
|
261
|
+
return new Promise((resolve) => {
|
|
262
|
+
// do some work
|
|
263
|
+
resolve({
|
|
264
|
+
name: args.name
|
|
265
|
+
});
|
|
266
|
+
});
|
|
267
|
+
},
|
|
268
|
+
|
|
269
|
+
// This is how to receive incoming headers
|
|
270
|
+
HeadersAwareFunction: function(args, cb, headers) {
|
|
271
|
+
return {
|
|
272
|
+
name: headers.Token
|
|
273
|
+
};
|
|
274
|
+
},
|
|
275
|
+
|
|
276
|
+
// You can also inspect the original `req`
|
|
277
|
+
reallyDetailedFunction: function(args, cb, headers, req) {
|
|
278
|
+
console.log('SOAP `reallyDetailedFunction` request from ' + req.connection.remoteAddress);
|
|
279
|
+
return {
|
|
280
|
+
name: headers.Token
|
|
281
|
+
};
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
};
|
|
293
286
|
|
|
294
|
-
var xml = require(
|
|
287
|
+
var xml = require('fs').readFileSync('myservice.wsdl', 'utf8');
|
|
295
288
|
|
|
296
|
-
//http server example
|
|
297
|
-
var server = http.createServer(function
|
|
298
|
-
|
|
299
|
-
});
|
|
289
|
+
//http server example
|
|
290
|
+
var server = http.createServer(function(request,response) {
|
|
291
|
+
response.end('404: Not Found: ' + request.url);
|
|
292
|
+
});
|
|
300
293
|
|
|
301
|
-
server.listen(8000);
|
|
302
|
-
soap.listen(server,
|
|
303
|
-
|
|
304
|
-
});
|
|
294
|
+
server.listen(8000);
|
|
295
|
+
soap.listen(server, '/wsdl', myService, xml, function(){
|
|
296
|
+
console.log('server initialized');
|
|
297
|
+
});
|
|
305
298
|
|
|
306
|
-
//express server example
|
|
307
|
-
var app = express();
|
|
308
|
-
//body parser middleware are supported (optional)
|
|
309
|
-
app.use(
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
);
|
|
317
|
-
app.listen(8001, function () {
|
|
318
|
-
//Note: /wsdl route will be handled by soap module
|
|
319
|
-
//and all other routes & middleware will continue to work
|
|
320
|
-
soap.listen(app, "/wsdl", myService, xml, function () {
|
|
321
|
-
console.log("server initialized");
|
|
299
|
+
//express server example
|
|
300
|
+
var app = express();
|
|
301
|
+
//body parser middleware are supported (optional)
|
|
302
|
+
app.use(bodyParser.raw({type: function(){return true;}, limit: '5mb'}));
|
|
303
|
+
app.listen(8001, function(){
|
|
304
|
+
//Note: /wsdl route will be handled by soap module
|
|
305
|
+
//and all other routes & middleware will continue to work
|
|
306
|
+
soap.listen(app, '/wsdl', myService, xml, function(){
|
|
307
|
+
console.log('server initialized');
|
|
308
|
+
});
|
|
322
309
|
});
|
|
323
|
-
|
|
310
|
+
|
|
324
311
|
```
|
|
325
312
|
|
|
326
|
-
```javascript
|
|
327
|
-
var xml = require(
|
|
313
|
+
``` javascript
|
|
314
|
+
var xml = require('fs').readFileSync('myservice.wsdl', 'utf8');
|
|
328
315
|
|
|
329
316
|
soap.listen(server, {
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
317
|
+
// Server options.
|
|
318
|
+
path: '/wsdl',
|
|
319
|
+
services: myService,
|
|
320
|
+
xml: xml,
|
|
321
|
+
|
|
322
|
+
// WSDL options.
|
|
323
|
+
attributesKey: 'theAttrs',
|
|
324
|
+
valueKey: 'theVal',
|
|
325
|
+
xmlKey: 'theXml'
|
|
339
326
|
});
|
|
340
327
|
```
|
|
341
328
|
|
|
342
329
|
### Server Logging
|
|
343
330
|
|
|
344
331
|
If the `log` method is defined, it will be called with:
|
|
345
|
-
|
|
346
332
|
- `type`: 'received', 'replied', 'info' or 'error'.
|
|
347
333
|
- `data`: The data to be logged which will be an XML for 'received' and 'replied' or a message for the other types.
|
|
348
334
|
- `req`: The original request object
|
|
349
335
|
|
|
350
|
-
```javascript
|
|
336
|
+
``` javascript
|
|
351
337
|
server = soap.listen(...)
|
|
352
338
|
server.log = function(type, data, req) {
|
|
353
339
|
// type is 'received', 'replied', 'info' or 'error'
|
|
@@ -358,11 +344,11 @@ If the `log` method is defined, it will be called with:
|
|
|
358
344
|
|
|
359
345
|
Server instances emit the following events:
|
|
360
346
|
|
|
361
|
-
|
|
347
|
+
* request - Emitted for every received messages.
|
|
362
348
|
The signature of the callback is `function(request, methodName)`.
|
|
363
|
-
|
|
349
|
+
* response - Emitted before sending SOAP response.
|
|
364
350
|
The signature of the callback is `function(response, methodName)`.
|
|
365
|
-
|
|
351
|
+
* headers - Emitted when the SOAP Headers are not empty.
|
|
366
352
|
The signature of the callback is `function(headers, methodName)`.
|
|
367
353
|
|
|
368
354
|
The sequence order of the calls is `request`, `headers` and then the dedicated
|
|
@@ -383,31 +369,31 @@ Pass in `oneWay` object in server options. Use the following keys:
|
|
|
383
369
|
A service method can reply with a SOAP Fault to a client by `throw`ing an
|
|
384
370
|
object with a `Fault` property.
|
|
385
371
|
|
|
386
|
-
```javascript
|
|
387
|
-
throw {
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
};
|
|
372
|
+
``` javascript
|
|
373
|
+
throw {
|
|
374
|
+
Fault: {
|
|
375
|
+
Code: {
|
|
376
|
+
Value: 'soap:Sender',
|
|
377
|
+
Subcode: { value: 'rpc:BadArguments' }
|
|
378
|
+
},
|
|
379
|
+
Reason: { Text: 'Processing Error' }
|
|
380
|
+
}
|
|
381
|
+
};
|
|
396
382
|
```
|
|
397
383
|
|
|
398
|
-
To change the HTTP statusCode of the response include it on the fault.
|
|
384
|
+
To change the HTTP statusCode of the response include it on the fault. The statusCode property will not be put on the xml message.
|
|
399
385
|
|
|
400
|
-
```javascript
|
|
401
|
-
throw {
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
};
|
|
386
|
+
``` javascript
|
|
387
|
+
throw {
|
|
388
|
+
Fault: {
|
|
389
|
+
Code: {
|
|
390
|
+
Value: 'soap:Sender',
|
|
391
|
+
Subcode: { value: 'rpc:BadArguments' }
|
|
392
|
+
},
|
|
393
|
+
Reason: { Text: 'Processing Error' },
|
|
394
|
+
statusCode: 500
|
|
395
|
+
}
|
|
396
|
+
};
|
|
411
397
|
```
|
|
412
398
|
|
|
413
399
|
### Server security example using PasswordDigest
|
|
@@ -415,8 +401,7 @@ throw {
|
|
|
415
401
|
If `server.authenticate` is not defined then no authentication will take place.
|
|
416
402
|
|
|
417
403
|
Asynchronous authentication:
|
|
418
|
-
|
|
419
|
-
```javascript
|
|
404
|
+
``` javascript
|
|
420
405
|
server = soap.listen(...)
|
|
421
406
|
server.authenticate = function(security, callback) {
|
|
422
407
|
var created, nonce, password, user, token;
|
|
@@ -435,8 +420,7 @@ Asynchronous authentication:
|
|
|
435
420
|
```
|
|
436
421
|
|
|
437
422
|
Synchronous authentication:
|
|
438
|
-
|
|
439
|
-
```javascript
|
|
423
|
+
``` javascript
|
|
440
424
|
server = soap.listen(...)
|
|
441
425
|
server.authenticate = function(security) {
|
|
442
426
|
var created, nonce, password, user, token;
|
|
@@ -452,20 +436,21 @@ The `server.authorizeConnection` method is called prior to the soap service meth
|
|
|
452
436
|
If the method is defined and returns `false` then the incoming connection is
|
|
453
437
|
terminated.
|
|
454
438
|
|
|
455
|
-
```javascript
|
|
439
|
+
``` javascript
|
|
456
440
|
server = soap.listen(...)
|
|
457
441
|
server.authorizeConnection = function(req) {
|
|
458
442
|
return true; // or false
|
|
459
443
|
};
|
|
460
444
|
```
|
|
461
445
|
|
|
446
|
+
|
|
462
447
|
## SOAP Headers
|
|
463
448
|
|
|
464
449
|
### Received SOAP Headers
|
|
465
450
|
|
|
466
451
|
A service method can look at the SOAP headers by providing a 3rd arguments.
|
|
467
452
|
|
|
468
|
-
```javascript
|
|
453
|
+
``` javascript
|
|
469
454
|
{
|
|
470
455
|
HeadersAwareFunction: function(args, cb, headers) {
|
|
471
456
|
return {
|
|
@@ -479,7 +464,7 @@ It is also possible to subscribe to the 'headers' event.
|
|
|
479
464
|
The event is triggered before the service method is called, and only when the
|
|
480
465
|
SOAP Headers are not empty.
|
|
481
466
|
|
|
482
|
-
```javascript
|
|
467
|
+
``` javascript
|
|
483
468
|
server = soap.listen(...)
|
|
484
469
|
server.on('headers', function(headers, methodName) {
|
|
485
470
|
// It is possible to change the value of the headers
|
|
@@ -497,21 +482,20 @@ second parameter is the name of the SOAP method that will called
|
|
|
497
482
|
Both client & server can define SOAP headers that will be added to what they send.
|
|
498
483
|
They provide the following methods to manage the headers.
|
|
499
484
|
|
|
500
|
-
#### _addSoapHeader_(soapHeader[, name, namespace, xmlns]) - add soapHeader to soap:Header node
|
|
501
485
|
|
|
486
|
+
#### *addSoapHeader*(soapHeader[, name, namespace, xmlns]) - add soapHeader to soap:Header node
|
|
502
487
|
##### Parameters
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
or function (server only)
|
|
488
|
+
- `soapHeader` Object({rootName: {name: 'value'}}), strict xml-string,
|
|
489
|
+
or function (server only)
|
|
506
490
|
|
|
507
491
|
For servers only, `soapHeader` can be a function, which allows headers to be
|
|
508
492
|
dynamically generated from information in the request. This function will be
|
|
509
493
|
called with the following arguments for each received request:
|
|
510
494
|
|
|
511
|
-
- `methodName`
|
|
512
|
-
- `args`
|
|
513
|
-
- `headers`
|
|
514
|
-
- `req`
|
|
495
|
+
- `methodName` The name of the request method
|
|
496
|
+
- `args` The arguments of the request
|
|
497
|
+
- `headers` The headers in the request
|
|
498
|
+
- `req` The original request object
|
|
515
499
|
|
|
516
500
|
The return value of the function must be an Object({rootName: {name: 'value'}})
|
|
517
501
|
or strict xml-string, which will be inserted as an outgoing header of the
|
|
@@ -519,7 +503,7 @@ response to that request.
|
|
|
519
503
|
|
|
520
504
|
For example:
|
|
521
505
|
|
|
522
|
-
```javascript
|
|
506
|
+
``` javascript
|
|
523
507
|
server = soap.listen(...);
|
|
524
508
|
server.addSoapHeader(function(methodName, args, headers, req) {
|
|
525
509
|
console.log('Adding headers for method', methodName);
|
|
@@ -532,61 +516,58 @@ For example:
|
|
|
532
516
|
```
|
|
533
517
|
|
|
534
518
|
##### Returns
|
|
535
|
-
|
|
536
519
|
The index where the header is inserted.
|
|
537
520
|
|
|
538
521
|
##### Optional parameters when first arg is object :
|
|
522
|
+
- `name` Unknown parameter (it could just a empty string)
|
|
523
|
+
- `namespace` prefix of xml namespace
|
|
524
|
+
- `xmlns` URI
|
|
539
525
|
|
|
540
|
-
|
|
541
|
-
- `namespace` prefix of xml namespace
|
|
542
|
-
- `xmlns` URI
|
|
543
|
-
|
|
544
|
-
#### _changeSoapHeader_(index, soapHeader[, name, namespace, xmlns]) - change an already existing soapHeader
|
|
545
|
-
|
|
526
|
+
#### *changeSoapHeader*(index, soapHeader[, name, namespace, xmlns]) - change an already existing soapHeader
|
|
546
527
|
##### Parameters
|
|
547
|
-
|
|
548
|
-
- `
|
|
549
|
-
|
|
550
|
-
or function (server only)
|
|
528
|
+
- `index` index of the header to replace with provided new value
|
|
529
|
+
- `soapHeader` Object({rootName: {name: 'value'}}), strict xml-string
|
|
530
|
+
or function (server only)
|
|
551
531
|
|
|
552
532
|
See `addSoapHeader` for how to pass a function into `soapHeader`.
|
|
553
533
|
|
|
554
|
-
####
|
|
534
|
+
#### *getSoapHeaders*() - return all defined headers
|
|
535
|
+
|
|
536
|
+
#### *clearSoapHeaders*() - remove all defined headers
|
|
555
537
|
|
|
556
|
-
#### _clearSoapHeaders_() - remove all defined headers
|
|
557
538
|
|
|
558
539
|
## Client
|
|
559
540
|
|
|
560
|
-
An instance of `Client` is passed to the `soap.createClient` callback.
|
|
541
|
+
An instance of `Client` is passed to the `soap.createClient` callback. It is used to execute methods on the soap service.
|
|
561
542
|
|
|
562
543
|
### Client.describe() - description of services, ports and methods as a JavaScript object
|
|
563
544
|
|
|
564
|
-
```javascript
|
|
565
|
-
client.describe()
|
|
566
|
-
{
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
545
|
+
``` javascript
|
|
546
|
+
client.describe() // returns
|
|
547
|
+
{
|
|
548
|
+
MyService: {
|
|
549
|
+
MyPort: {
|
|
550
|
+
MyFunction: {
|
|
551
|
+
input: {
|
|
552
|
+
name: 'string'
|
|
553
|
+
}
|
|
554
|
+
}
|
|
572
555
|
}
|
|
573
556
|
}
|
|
574
557
|
}
|
|
575
|
-
}
|
|
576
|
-
}
|
|
577
558
|
```
|
|
578
559
|
|
|
579
560
|
### Client.setSecurity(security) - use the specified security protocol
|
|
580
561
|
|
|
581
562
|
See [Security](#security) for example usage.
|
|
582
563
|
|
|
583
|
-
### Client
|
|
564
|
+
### Client.*method*(args, callback, options) - call *method* on the SOAP service.
|
|
584
565
|
|
|
585
|
-
- `args` (
|
|
586
|
-
- `callback` (
|
|
587
|
-
- `options` (
|
|
588
|
-
- `forever` (
|
|
589
|
-
- `attachments` (
|
|
566
|
+
- `args` (*Object*): Arguments that generate an XML document inside of the SOAP Body section.
|
|
567
|
+
- `callback` (*Function*)
|
|
568
|
+
- `options` (*Object*): Set options for the request module on WSDL requests. If using the default request module, see [Request Config | Axios Docs](https://axios-http.com/docs/req_config). Additional options supported by `node-soap` are documented below:
|
|
569
|
+
- `forever` (*boolean*): Enables keep-alive connections and pools them
|
|
570
|
+
- `attachments` (*Array*): array of attachment objects. This converts the request into MTOM: _headers['Content-Type']='multipart/related; type="application/xop+xml"; start= ... '_
|
|
590
571
|
```
|
|
591
572
|
[{
|
|
592
573
|
mimetype: content mimetype,
|
|
@@ -597,45 +578,41 @@ See [Security](#security) for example usage.
|
|
|
597
578
|
...
|
|
598
579
|
]
|
|
599
580
|
```
|
|
600
|
-
- `forceMTOM` (
|
|
601
|
-
- `forceGzip` (
|
|
581
|
+
- `forceMTOM` (*boolean*): Send the request as MTOM even if you don't have attachments.
|
|
582
|
+
- `forceGzip` (*boolean*): Force transfer-encoding in gzip. (**Default:** `false`)
|
|
602
583
|
|
|
603
584
|
#### Example
|
|
604
585
|
|
|
605
|
-
```javascript
|
|
606
|
-
client.MyFunction(
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
// rawRequest is the raw xml request string
|
|
613
|
-
}
|
|
614
|
-
);
|
|
586
|
+
``` javascript
|
|
587
|
+
client.MyFunction({name: 'value'}, function(err, result, rawResponse, soapHeader, rawRequest) {
|
|
588
|
+
// result is a javascript object
|
|
589
|
+
// rawResponse is the raw xml response string
|
|
590
|
+
// soapHeader is the response soap header as a javascript object
|
|
591
|
+
// rawRequest is the raw xml request string
|
|
592
|
+
})
|
|
615
593
|
```
|
|
616
594
|
|
|
617
|
-
### Client.*method*Async(args, options) - call
|
|
595
|
+
### Client.*method*Async(args, options) - call *method* on the SOAP service.
|
|
618
596
|
|
|
619
|
-
- `args` (
|
|
620
|
-
- `options` (
|
|
597
|
+
- `args` (*Object*): Arguments that generate an XML document inside of the SOAP Body section.
|
|
598
|
+
- `options` (*Object*): See [Client.*method*(args, callback, options) - call *method* on the SOAP service.](#clientmethodargs-callback-options---call-method-on-the-soap-service) for a description.
|
|
621
599
|
|
|
622
600
|
#### Example
|
|
623
601
|
|
|
624
|
-
```javascript
|
|
625
|
-
client.MyFunctionAsync({
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
})
|
|
602
|
+
``` javascript
|
|
603
|
+
client.MyFunctionAsync({name: 'value'}).then((result) => {
|
|
604
|
+
// result is a javascript array containing result, rawResponse, soapheader, and rawRequest
|
|
605
|
+
// result is a javascript object
|
|
606
|
+
// rawResponse is the raw xml response string
|
|
607
|
+
// soapHeader is the response soap header as a javascript object
|
|
608
|
+
// rawRequest is the raw xml request string
|
|
609
|
+
})
|
|
632
610
|
```
|
|
633
611
|
|
|
634
612
|
##### Example with JSON for the `args`
|
|
635
|
-
|
|
636
613
|
The example above uses `{name: 'value'}` as the args. This may generate a SOAP messages such as:
|
|
637
614
|
|
|
638
|
-
```javascript
|
|
615
|
+
``` javascript
|
|
639
616
|
<?xml version="1.0" encoding="utf-8"?>
|
|
640
617
|
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
|
641
618
|
<soapenv:Body>
|
|
@@ -646,13 +623,12 @@ The example above uses `{name: 'value'}` as the args. This may generate a SOAP m
|
|
|
646
623
|
</soapenv:Envelope>
|
|
647
624
|
```
|
|
648
625
|
|
|
649
|
-
Note that the "Request" element in the output above comes from the WSDL.
|
|
626
|
+
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`).
|
|
650
627
|
|
|
651
628
|
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.
|
|
652
629
|
|
|
653
630
|
##### Example with XML String for the `args`
|
|
654
|
-
|
|
655
|
-
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">`).
|
|
631
|
+
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">`).
|
|
656
632
|
|
|
657
633
|
```
|
|
658
634
|
var args = { _xml: "<ns1:MyRootElement xmlns:ns1="http://www.example.com/v1/ns1">
|
|
@@ -660,97 +636,98 @@ You may pass in a fully-formed XML string instead the individual elements in JSO
|
|
|
660
636
|
</ns1:MyRootElement>"
|
|
661
637
|
};
|
|
662
638
|
```
|
|
639
|
+
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.
|
|
663
640
|
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
### Client._service_._port_._method_(args, callback[, options[, extraHeaders]]) - call a _method_ using a specific _service_ and _port_
|
|
641
|
+
### Client.*service*.*port*.*method*(args, callback[, options[, extraHeaders]]) - call a *method* using a specific *service* and *port*
|
|
667
642
|
|
|
668
|
-
- `args` (
|
|
669
|
-
- `callback` (
|
|
670
|
-
- `options` (
|
|
671
|
-
- `extraHeaders` (
|
|
643
|
+
- `args` (*Object*): Arguments that generate an XML document inside of the SOAP Body section.
|
|
644
|
+
- `callback` (*Function*)
|
|
645
|
+
- `options` (*Object*): See [Client.*method*(args, callback, options) - call *method* on the SOAP service.](#clientmethodargs-callback-options---call-method-on-the-soap-service) for a description.
|
|
646
|
+
- `extraHeaders` (*Object*): Sets HTTP headers for the WSDL request.
|
|
672
647
|
|
|
673
648
|
#### Example
|
|
674
649
|
|
|
675
|
-
```javascript
|
|
676
|
-
client.MyService.MyPort.MyFunction({
|
|
677
|
-
|
|
678
|
-
})
|
|
650
|
+
``` javascript
|
|
651
|
+
client.MyService.MyPort.MyFunction({name: 'value'}, function(err, result) {
|
|
652
|
+
// result is a javascript object
|
|
653
|
+
})
|
|
679
654
|
```
|
|
680
655
|
|
|
681
656
|
#### Options (optional)
|
|
682
|
-
|
|
683
|
-
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
{ name: "value" },
|
|
689
|
-
function (err, result) {
|
|
690
|
-
// result is a javascript object
|
|
691
|
-
},
|
|
692
|
-
{ timeout: 5000 }
|
|
693
|
-
);
|
|
657
|
+
- Accepts any option that the request module accepts, see [here.](https://github.com/mikeal/request)
|
|
658
|
+
- For example, you could set a timeout of 5 seconds on the request like this:
|
|
659
|
+
``` javascript
|
|
660
|
+
client.MyService.MyPort.MyFunction({name: 'value'}, function(err, result) {
|
|
661
|
+
// result is a javascript object
|
|
662
|
+
}, {timeout: 5000})
|
|
694
663
|
```
|
|
695
664
|
|
|
696
665
|
- You can measure the elapsed time on the request by passing the time option:
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
client.
|
|
700
|
-
{
|
|
701
|
-
function (err, result) {
|
|
702
|
-
// client.lastElapsedTime - the elapsed time of the last request in milliseconds
|
|
703
|
-
},
|
|
704
|
-
{ time: true }
|
|
705
|
-
);
|
|
666
|
+
``` javascript
|
|
667
|
+
client.MyService.MyPort.MyFunction({name: 'value'}, function(err, result) {
|
|
668
|
+
// client.lastElapsedTime - the elapsed time of the last request in milliseconds
|
|
669
|
+
}, {time: true})
|
|
706
670
|
```
|
|
707
671
|
|
|
708
672
|
- Also, you could pass your soap request through a debugging proxy such as [Fiddler](http://www.telerik.com/fiddler) or [Betwixt](https://github.com/kdzwinel/betwixt).
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
client.
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
password: "rapunz3l",
|
|
724
|
-
},
|
|
725
|
-
},
|
|
726
|
-
}
|
|
727
|
-
);
|
|
673
|
+
``` javascript
|
|
674
|
+
client.MyService.MyPort.MyFunction({name: 'value'}, function(err, result) {
|
|
675
|
+
// client.lastElapsedTime - the elapsed time of the last request in milliseconds
|
|
676
|
+
}, {
|
|
677
|
+
proxy: {
|
|
678
|
+
protocol: 'https',
|
|
679
|
+
host: '127.0.0.1',
|
|
680
|
+
port: 9000,
|
|
681
|
+
auth: {
|
|
682
|
+
username: 'mikeymike',
|
|
683
|
+
password: 'rapunz3l'
|
|
684
|
+
}
|
|
685
|
+
}
|
|
686
|
+
})
|
|
728
687
|
```
|
|
729
688
|
|
|
730
689
|
- You can modify xml (string) before call:
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
client.
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
690
|
+
``` javascript
|
|
691
|
+
client.MyService.MyPort.MyFunction({name: 'value'}, function(err, result) {
|
|
692
|
+
// client.lastElapsedTime - the elapsed time of the last request in milliseconds
|
|
693
|
+
}, {postProcess: function(_xml) {
|
|
694
|
+
return _xml.replace('text', 'newtext');
|
|
695
|
+
}})
|
|
696
|
+
```
|
|
697
|
+
|
|
698
|
+
- Making `postProcess` either synchronous or asynchronous with a `Promise`:
|
|
699
|
+
- Synchronous (classic):
|
|
700
|
+
```javascript
|
|
701
|
+
// ...
|
|
702
|
+
client.registerUser(requestBody, {
|
|
703
|
+
postProcess: (xml) => {
|
|
704
|
+
const testString = "Jane"
|
|
705
|
+
xml = xml.replace("John", testString)
|
|
706
|
+
return xml;
|
|
707
|
+
}
|
|
708
|
+
}
|
|
709
|
+
// ...
|
|
710
|
+
```
|
|
711
|
+
- Asynchronous (resolves promise on async invoke of `postProcess`):
|
|
712
|
+
```javascript
|
|
713
|
+
// ...
|
|
714
|
+
client.registerUser(requestBody, {
|
|
715
|
+
postProcess: async (xml) => {
|
|
716
|
+
const testString = await new Promise(resolve => setTimeout(() => resolve("Jane"), 50));
|
|
717
|
+
xml = xml.replace("John", testString)
|
|
718
|
+
return xml;
|
|
719
|
+
}
|
|
720
|
+
}
|
|
721
|
+
// ...
|
|
722
|
+
```
|
|
745
723
|
|
|
746
724
|
#### Extra Headers (optional)
|
|
747
725
|
|
|
748
726
|
Object properties define extra HTTP headers to be sent on the request.
|
|
749
727
|
|
|
750
728
|
- Add custom User-Agent:
|
|
751
|
-
|
|
752
729
|
```javascript
|
|
753
|
-
client.addHttpHeader(
|
|
730
|
+
client.addHttpHeader('User-Agent', `CustomUserAgent`);
|
|
754
731
|
```
|
|
755
732
|
|
|
756
733
|
#### Alternative method call using callback-last pattern
|
|
@@ -758,81 +735,57 @@ client.addHttpHeader("User-Agent", `CustomUserAgent`);
|
|
|
758
735
|
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:
|
|
759
736
|
|
|
760
737
|
```javascript
|
|
761
|
-
client.MyService.MyPort.MyFunction(
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
function (err, result) {
|
|
765
|
-
// result is a javascript object
|
|
766
|
-
}
|
|
767
|
-
);
|
|
738
|
+
client.MyService.MyPort.MyFunction({name: 'value'}, options, function (err, result) {
|
|
739
|
+
// result is a javascript object
|
|
740
|
+
})
|
|
768
741
|
|
|
769
|
-
client.MyService.MyPort.MyFunction(
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
extraHeaders,
|
|
773
|
-
function (err, result) {
|
|
774
|
-
// result is a javascript object
|
|
775
|
-
}
|
|
776
|
-
);
|
|
742
|
+
client.MyService.MyPort.MyFunction({name: 'value'}, options, extraHeaders, function (err, result) {
|
|
743
|
+
// result is a javascript object
|
|
744
|
+
})
|
|
777
745
|
```
|
|
778
746
|
|
|
779
747
|
### Overriding the namespace prefix
|
|
780
|
-
|
|
781
|
-
`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.:
|
|
748
|
+
`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.:
|
|
782
749
|
|
|
783
750
|
```javascript
|
|
784
|
-
client.MyService.MyPort.MyFunction(
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
// request body sent with `<ns1:name`, regardless of what the namespace should have been.
|
|
788
|
-
},
|
|
789
|
-
{ timeout: 5000 }
|
|
790
|
-
);
|
|
751
|
+
client.MyService.MyPort.MyFunction({'ns1:name': 'value'}, function(err, result) {
|
|
752
|
+
// request body sent with `<ns1:name`, regardless of what the namespace should have been.
|
|
753
|
+
}, {timeout: 5000})
|
|
791
754
|
```
|
|
792
755
|
|
|
793
756
|
- Remove namespace prefix of param
|
|
794
757
|
|
|
795
758
|
```javascript
|
|
796
|
-
client.MyService.MyPort.MyFunction(
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
// request body sent with `<name`, regardless of what the namespace should have been.
|
|
800
|
-
},
|
|
801
|
-
{ timeout: 5000 }
|
|
802
|
-
);
|
|
759
|
+
client.MyService.MyPort.MyFunction({':name': 'value'}, function(err, result) {
|
|
760
|
+
// request body sent with `<name`, regardless of what the namespace should have been.
|
|
761
|
+
}, {timeout: 5000})
|
|
803
762
|
```
|
|
804
763
|
|
|
805
|
-
### Client
|
|
764
|
+
### Client.*lastRequest* - the property that contains last full soap request for client logging
|
|
806
765
|
|
|
807
766
|
### Client.setEndpoint(url) - overwrite the SOAP service endpoint address
|
|
808
767
|
|
|
809
768
|
### Client Events
|
|
810
|
-
|
|
811
769
|
Client instances emit the following events:
|
|
812
770
|
|
|
813
771
|
### _request_
|
|
814
|
-
|
|
815
772
|
Emitted before a request is sent. The event handler has the signature `(xml, eid)`.
|
|
816
773
|
|
|
817
774
|
- _xml_ - The entire Soap request (Envelope) including headers.
|
|
818
775
|
- _eid_ - The exchange id.
|
|
819
776
|
|
|
820
777
|
### _message_
|
|
821
|
-
|
|
822
778
|
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)`.
|
|
823
779
|
|
|
824
780
|
- _message_ - Soap body contents.
|
|
825
781
|
- _eid_ - The exchange id.
|
|
826
782
|
|
|
827
783
|
### _soapError_
|
|
828
|
-
|
|
829
784
|
Emitted when an erroneous response is received. Useful if you want to globally log errors. The event handler has the signature `(error, eid)`.
|
|
830
785
|
|
|
831
786
|
- _error_ - An error object which also contains the resoponse.
|
|
832
787
|
- _eid_ - The exchange id.
|
|
833
|
-
|
|
834
788
|
### _response_
|
|
835
|
-
|
|
836
789
|
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)`
|
|
837
790
|
|
|
838
791
|
- _body_ - The SOAP response body.
|
|
@@ -849,9 +802,9 @@ By default exchange ids are generated by using node-uuid but you can use options
|
|
|
849
802
|
Example :
|
|
850
803
|
|
|
851
804
|
```javascript
|
|
852
|
-
client.MyService.MyPort.MyFunction(args, function
|
|
853
|
-
|
|
854
|
-
})
|
|
805
|
+
client.MyService.MyPort.MyFunction(args , function(err, result) {
|
|
806
|
+
|
|
807
|
+
}, {exchangeId: myExchangeId})
|
|
855
808
|
```
|
|
856
809
|
|
|
857
810
|
## WSDL
|
|
@@ -864,20 +817,18 @@ services).
|
|
|
864
817
|
## WSDL.constructor(wsdl, baseURL, options):
|
|
865
818
|
|
|
866
819
|
Construct a WSDL instance from either the WSDL content or the URL to the WSDL.
|
|
867
|
-
|
|
868
820
|
#### Parameters
|
|
869
821
|
|
|
870
|
-
- wsdl: A string wSDL or an URL to the WSDL
|
|
871
|
-
- baseURL: base URL for the SOAP API
|
|
872
|
-
- options: options (see source for details), use `{}` as default.
|
|
822
|
+
- wsdl: A string wSDL or an URL to the WSDL
|
|
823
|
+
- baseURL: base URL for the SOAP API
|
|
824
|
+
- options: options (see source for details), use `{}` as default.
|
|
873
825
|
|
|
874
826
|
### wsdl.xmlToObject(xml):
|
|
875
827
|
|
|
876
828
|
Unmarshal XML to object.
|
|
877
829
|
|
|
878
830
|
#### Parameters:
|
|
879
|
-
|
|
880
|
-
- xml: SOAP response (XML) to unmarshal
|
|
831
|
+
- xml: SOAP response (XML) to unmarshal
|
|
881
832
|
|
|
882
833
|
#### Returns:
|
|
883
834
|
|
|
@@ -888,18 +839,16 @@ Object containing the object types from the xml as keys.
|
|
|
888
839
|
Marshal an object to XML
|
|
889
840
|
|
|
890
841
|
#### Parameters:
|
|
891
|
-
|
|
892
|
-
-
|
|
893
|
-
-
|
|
894
|
-
-
|
|
895
|
-
- namespaceURI: URI of the namespace
|
|
842
|
+
- object: Object to marshal
|
|
843
|
+
- typeName: type (as per the wsdl) of the object
|
|
844
|
+
- namespacePrefix: namespace prefix
|
|
845
|
+
- namespaceURI: URI of the namespace
|
|
896
846
|
|
|
897
847
|
#### Returns:
|
|
898
848
|
|
|
899
849
|
XML representation of object.
|
|
900
850
|
|
|
901
851
|
#### Example:
|
|
902
|
-
|
|
903
852
|
```typescript
|
|
904
853
|
// Abstracted from a real use case
|
|
905
854
|
import { AxiosInstance } from 'axios';
|
|
@@ -939,169 +888,154 @@ async function samplePostCall(prospect: IProspectType) {
|
|
|
939
888
|
}
|
|
940
889
|
```
|
|
941
890
|
|
|
942
|
-
## Security
|
|
943
891
|
|
|
944
|
-
|
|
945
|
-
as well. The interface is quite simple. Each protocol defines these optional methods:
|
|
892
|
+
## Security
|
|
946
893
|
|
|
947
|
-
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
894
|
+
`node-soap` has several default security protocols. You can easily add your own
|
|
895
|
+
as well. The interface is quite simple. Each protocol defines these optional methods:
|
|
896
|
+
* `addOptions(options)` - a method that accepts an options arg that is eventually passed directly to `request`.
|
|
897
|
+
* `addHeaders(headers)` - a method that accepts an argument with HTTP headers, to add new ones.
|
|
898
|
+
* `toXML()` - a method that returns a string of XML to be appended to the SOAP headers. Not executed if `postProcess` is also defined.
|
|
899
|
+
* `postProcess(xml, envelopeKey)` - a method that receives the the assembled request XML plus envelope key, and returns a processed string of XML. Executed before `options.postProcess`.
|
|
951
900
|
|
|
952
901
|
### BasicAuthSecurity
|
|
953
902
|
|
|
954
|
-
```javascript
|
|
955
|
-
client.setSecurity(new soap.BasicAuthSecurity(
|
|
903
|
+
``` javascript
|
|
904
|
+
client.setSecurity(new soap.BasicAuthSecurity('username', 'password'));
|
|
956
905
|
```
|
|
957
906
|
|
|
958
907
|
### BearerSecurity
|
|
959
908
|
|
|
960
|
-
```javascript
|
|
961
|
-
client.setSecurity(new soap.BearerSecurity(
|
|
909
|
+
``` javascript
|
|
910
|
+
client.setSecurity(new soap.BearerSecurity('token'));
|
|
962
911
|
```
|
|
963
912
|
|
|
964
913
|
### ClientSSLSecurity
|
|
965
914
|
|
|
966
915
|
_Note_: If you run into issues using this protocol, consider passing these options
|
|
967
916
|
as default request options to the constructor:
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
- `secureOptions: constants.SSL_OP_NO_TLSv1_2` (this is likely needed for node >= 10.0)
|
|
917
|
+
* `rejectUnauthorized: false`
|
|
918
|
+
* `strictSSL: false`
|
|
919
|
+
* `secureOptions: constants.SSL_OP_NO_TLSv1_2` (this is likely needed for node >= 10.0)
|
|
972
920
|
|
|
973
921
|
If you want to reuse tls sessions, you can use the option `forever: true`.
|
|
974
922
|
|
|
975
|
-
```javascript
|
|
976
|
-
client.setSecurity(
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
}
|
|
990
|
-
)
|
|
991
|
-
);
|
|
923
|
+
``` javascript
|
|
924
|
+
client.setSecurity(new soap.ClientSSLSecurity(
|
|
925
|
+
'/path/to/key',
|
|
926
|
+
'path/to/cert',
|
|
927
|
+
'/path/to/ca-cert', /*or an array of buffer: [fs.readFileSync('/path/to/ca-cert/1', 'utf8'),
|
|
928
|
+
'fs.readFileSync('/path/to/ca-cert/2', 'utf8')], */
|
|
929
|
+
{ /*default request options like */
|
|
930
|
+
// strictSSL: true,
|
|
931
|
+
// rejectUnauthorized: false,
|
|
932
|
+
// hostname: 'some-hostname'
|
|
933
|
+
// secureOptions: constants.SSL_OP_NO_TLSv1_2,
|
|
934
|
+
// forever: true,
|
|
935
|
+
},
|
|
936
|
+
));
|
|
992
937
|
```
|
|
993
938
|
|
|
994
939
|
### ClientSSLSecurityPFX
|
|
995
940
|
|
|
996
941
|
_Note_: If you run into issues using this protocol, consider passing these options
|
|
997
942
|
as default request options to the constructor:
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
- `secureOptions: constants.SSL_OP_NO_TLSv1_2` (this is likely needed for node >= 10.0)
|
|
943
|
+
* `rejectUnauthorized: false`
|
|
944
|
+
* `strictSSL: false`
|
|
945
|
+
* `secureOptions: constants.SSL_OP_NO_TLSv1_2` (this is likely needed for node >= 10.0)
|
|
1002
946
|
|
|
1003
947
|
If you want to reuse tls sessions, you can use the option `forever: true`.
|
|
1004
948
|
|
|
1005
|
-
```javascript
|
|
1006
|
-
client.setSecurity(
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
}
|
|
1018
|
-
)
|
|
1019
|
-
);
|
|
949
|
+
``` javascript
|
|
950
|
+
client.setSecurity(new soap.ClientSSLSecurityPFX(
|
|
951
|
+
'/path/to/pfx/cert', // or a buffer: [fs.readFileSync('/path/to/pfx/cert', 'utf8'),
|
|
952
|
+
'path/to/optional/passphrase',
|
|
953
|
+
{ /*default request options like */
|
|
954
|
+
// strictSSL: true,
|
|
955
|
+
// rejectUnauthorized: false,
|
|
956
|
+
// hostname: 'some-hostname'
|
|
957
|
+
// secureOptions: constants.SSL_OP_NO_TLSv1_2,
|
|
958
|
+
// forever: true,
|
|
959
|
+
},
|
|
960
|
+
));
|
|
1020
961
|
```
|
|
1021
962
|
|
|
1022
963
|
### WSSecurity
|
|
1023
964
|
|
|
1024
965
|
`WSSecurity` implements WS-Security. UsernameToken and PasswordText/PasswordDigest is supported.
|
|
1025
966
|
|
|
1026
|
-
```javascript
|
|
1027
|
-
var options = {
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
};
|
|
1031
|
-
var wsSecurity = new soap.WSSecurity(
|
|
1032
|
-
client.setSecurity(wsSecurity);
|
|
967
|
+
``` javascript
|
|
968
|
+
var options = {
|
|
969
|
+
hasNonce: true,
|
|
970
|
+
actor: 'actor'
|
|
971
|
+
};
|
|
972
|
+
var wsSecurity = new soap.WSSecurity('username', 'password', options)
|
|
973
|
+
client.setSecurity(wsSecurity);
|
|
1033
974
|
```
|
|
1034
|
-
|
|
1035
975
|
the `options` object is optional and can contain the following properties:
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
- `actor`: if set, adds Actor attribute with given value to security tag (default: `''`)
|
|
976
|
+
* `passwordType`: 'PasswordDigest' or 'PasswordText' (default: `'PasswordText'`)
|
|
977
|
+
* `hasTimeStamp`: adds Timestamp element (default: `true`)
|
|
978
|
+
* `hasTokenCreated`: adds Created element (default: `true`)
|
|
979
|
+
* `hasNonce`: adds Nonce element (default: `false`)
|
|
980
|
+
* `mustUnderstand`: adds mustUnderstand=1 attribute to security tag (default: `false`)
|
|
981
|
+
* `actor`: if set, adds Actor attribute with given value to security tag (default: `''`)
|
|
1043
982
|
|
|
1044
983
|
### WSSecurityCert
|
|
1045
984
|
|
|
1046
985
|
WS-Security X509 Certificate support.
|
|
1047
986
|
|
|
1048
|
-
```javascript
|
|
1049
|
-
var privateKey = fs.readFileSync(privateKeyPath);
|
|
1050
|
-
var publicKey = fs.readFileSync(publicKeyPath);
|
|
1051
|
-
var password =
|
|
1052
|
-
var options = {
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
options
|
|
1068
|
-
);
|
|
1069
|
-
client.setSecurity(wsSecurity);
|
|
987
|
+
``` javascript
|
|
988
|
+
var privateKey = fs.readFileSync(privateKeyPath);
|
|
989
|
+
var publicKey = fs.readFileSync(publicKeyPath);
|
|
990
|
+
var password = ''; // optional password
|
|
991
|
+
var options = {
|
|
992
|
+
hasTimeStamp: true,
|
|
993
|
+
additionalReferences: [
|
|
994
|
+
'wsa:Action',
|
|
995
|
+
'wsa:ReplyTo',
|
|
996
|
+
'wsa:To',
|
|
997
|
+
],
|
|
998
|
+
signerOptions: {
|
|
999
|
+
prefix: 'ds',
|
|
1000
|
+
attrs: { Id: 'Signature' },
|
|
1001
|
+
existingPrefixes: {
|
|
1002
|
+
wsse: 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd',
|
|
1003
|
+
}
|
|
1004
|
+
}
|
|
1005
|
+
}
|
|
1006
|
+
var wsSecurity = new soap.WSSecurityCert(privateKey, publicKey, password, options);
|
|
1007
|
+
client.setSecurity(wsSecurity);
|
|
1070
1008
|
```
|
|
1071
1009
|
|
|
1072
1010
|
The `options` object is optional and can contain the following properties:
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
- `idMode`: (optional) either 'wssecurity' to generate wsse-scoped reference Id on <Body> or undefined for an unscoped reference Id
|
|
1011
|
+
* `hasTimeStamp`: Includes Timestamp tags (default: `true`)
|
|
1012
|
+
* `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 array
|
|
1013
|
+
* `signatureAlgorithm`: set to `http://www.w3.org/2001/04/xmldsig-more#rsa-sha256` to use sha256
|
|
1014
|
+
* `digestAlgorithm`: set to `http://www.w3.org/2000/09/xmldsig#sha1` to use sha1 (default `http://www.w3.org/2001/04/xmlenc#sha256`)
|
|
1015
|
+
* `additionalReferences` : (optional) Array of Soap headers that need to be signed. This need to be added using `client.addSoapHeader('header')`
|
|
1016
|
+
* `excludeReferencesFromSigning`: (Optional) An array of SOAP element names to exclude from signing (e.g., `Body`, `Timestamp`, `To`, `Action`).
|
|
1017
|
+
* `signerOptions`: (optional) passes options to the XML Signer package - from (https://github.com/yaronn/xml-crypto)
|
|
1018
|
+
* `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' }`)
|
|
1019
|
+
* `prefix`: (optional) Adds this value as a prefix for the generated signature tags.
|
|
1020
|
+
* `attrs`: (optional) A hash of attributes and values attrName: value to add to the signature root node
|
|
1021
|
+
* `idMode`: (optional) either 'wssecurity' to generate wsse-scoped reference Id on <Body> or undefined for an unscoped reference Id
|
|
1085
1022
|
|
|
1086
1023
|
### WSSecurityPlusCert
|
|
1087
1024
|
|
|
1088
1025
|
Use WSSecurity and WSSecurityCert together.
|
|
1089
1026
|
|
|
1090
|
-
```javascript
|
|
1091
|
-
var wsSecurity = new soap.WSSecurity(/* see WSSecurity above */);
|
|
1092
|
-
var wsSecurityCert = new soap.WSSecurityCert(/* see WSSecurityCert above */);
|
|
1093
|
-
var wsSecurityPlusCert = new soap.WSSecurityPlusCert(
|
|
1094
|
-
|
|
1095
|
-
wsSecurityCert
|
|
1096
|
-
);
|
|
1097
|
-
client.setSecurity(wsSecurityPlusCert);
|
|
1027
|
+
``` javascript
|
|
1028
|
+
var wsSecurity = new soap.WSSecurity(/* see WSSecurity above */);
|
|
1029
|
+
var wsSecurityCert = new soap.WSSecurityCert(/* see WSSecurityCert above */);
|
|
1030
|
+
var wsSecurityPlusCert = new soap.WSSecurityPlusCert(wsSecurity, wsSecurityCert);
|
|
1031
|
+
client.setSecurity(wsSecurityPlusCert);
|
|
1098
1032
|
```
|
|
1099
1033
|
|
|
1100
1034
|
#### Option examples
|
|
1101
1035
|
|
|
1102
1036
|
`hasTimeStamp:true`
|
|
1103
1037
|
|
|
1104
|
-
```xml
|
|
1038
|
+
``` xml
|
|
1105
1039
|
<soap:Header>
|
|
1106
1040
|
<wsse:Security soap:mustUnderstand="1">
|
|
1107
1041
|
<wsse:BinarySecurityToken>XXX</wsse:BinarySecurityToken>
|
|
@@ -1128,8 +1062,7 @@ client.setSecurity(wsSecurityPlusCert);
|
|
|
1128
1062
|
```
|
|
1129
1063
|
|
|
1130
1064
|
`additionalReferences: ['To']`
|
|
1131
|
-
|
|
1132
|
-
```XML
|
|
1065
|
+
``` XML
|
|
1133
1066
|
<soap:Header>
|
|
1134
1067
|
<To Id="To">localhost.com</To>
|
|
1135
1068
|
<wsse:Security soap:mustUnderstand="1">
|
|
@@ -1165,7 +1098,7 @@ client.setSecurity(wsSecurityPlusCert);
|
|
|
1165
1098
|
|
|
1166
1099
|
`signerOptions.prefix:'ds'`
|
|
1167
1100
|
|
|
1168
|
-
```XML
|
|
1101
|
+
``` XML
|
|
1169
1102
|
<soap:Header>
|
|
1170
1103
|
<To Id="To">localhost.com</To>
|
|
1171
1104
|
<wsse:Security soap:mustUnderstand="1">
|
|
@@ -1201,7 +1134,7 @@ client.setSecurity(wsSecurityPlusCert);
|
|
|
1201
1134
|
|
|
1202
1135
|
`signerOptions.attrs:{ Id: 'signature-100', foo:'bar'}`
|
|
1203
1136
|
|
|
1204
|
-
```xml
|
|
1137
|
+
``` xml
|
|
1205
1138
|
<soap:Header>
|
|
1206
1139
|
<wsse:Security soap:mustUnderstand="1">
|
|
1207
1140
|
<wsse:BinarySecurityToken>XXX</wsse:BinarySecurityToken>
|
|
@@ -1226,12 +1159,11 @@ client.setSecurity(wsSecurityPlusCert);
|
|
|
1226
1159
|
</wsse:Security>
|
|
1227
1160
|
</soap:Header>
|
|
1228
1161
|
```
|
|
1229
|
-
|
|
1230
1162
|
### WSSecurityCertWithToken
|
|
1231
1163
|
|
|
1232
1164
|
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.
|
|
1233
1165
|
|
|
1234
|
-
```xml
|
|
1166
|
+
``` xml
|
|
1235
1167
|
<wsse:UsernameToken>
|
|
1236
1168
|
<wsse:Username>someusername</wsse:Username>
|
|
1237
1169
|
<wsse:Password>someusername's password</wsse:Password>
|
|
@@ -1241,68 +1173,47 @@ WS-Security X509 Certificate support. Just like WSSecurityCert, except that it a
|
|
|
1241
1173
|
### NTLMSecurity
|
|
1242
1174
|
|
|
1243
1175
|
Parameter invocation:
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
client.setSecurity(
|
|
1247
|
-
new soap.NTLMSecurity("username", "password", "domain", "workstation")
|
|
1248
|
-
);
|
|
1176
|
+
``` javascript
|
|
1177
|
+
client.setSecurity(new soap.NTLMSecurity('username', 'password', 'domain', 'workstation'));
|
|
1249
1178
|
```
|
|
1250
|
-
|
|
1251
1179
|
This can also be set up with a JSON object, substituting values as appropriate, for example:
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
username: "username",
|
|
1256
|
-
password: "password",
|
|
1257
|
-
domain: "domain",
|
|
1258
|
-
workstation: "workstation",
|
|
1259
|
-
};
|
|
1260
|
-
client.setSecurity(new soap.NTLMSecurity(loginData));
|
|
1180
|
+
``` javascript
|
|
1181
|
+
var loginData = {username: 'username', password: 'password', domain: 'domain', workstation: 'workstation'};
|
|
1182
|
+
client.setSecurity(new soap.NTLMSecurity(loginData));
|
|
1261
1183
|
```
|
|
1262
1184
|
|
|
1263
1185
|
## Handling XML Attributes, Value and XML (wsdlOptions).
|
|
1264
|
-
|
|
1265
1186
|
Sometimes it is necessary to override the default behaviour of `node-soap` in order to deal with the special requirements
|
|
1266
1187
|
of your code base or a third library you use. Therefore you can use the `wsdlOptions` Object, which is passed in the
|
|
1267
1188
|
`#createClient()` method and could have any (or all) of the following contents:
|
|
1268
|
-
|
|
1269
1189
|
```javascript
|
|
1270
1190
|
var wsdlOptions = {
|
|
1271
|
-
attributesKey:
|
|
1272
|
-
valueKey:
|
|
1273
|
-
xmlKey:
|
|
1274
|
-
}
|
|
1191
|
+
attributesKey: 'theAttrs',
|
|
1192
|
+
valueKey: 'theVal',
|
|
1193
|
+
xmlKey: 'theXml'
|
|
1194
|
+
}
|
|
1275
1195
|
```
|
|
1276
|
-
|
|
1277
1196
|
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.
|
|
1278
1197
|
|
|
1279
1198
|
### Overriding the `value` key
|
|
1280
|
-
|
|
1281
1199
|
By default, `node-soap` uses `$value` as the key for any parsed XML value which may interfere with your other code as it
|
|
1282
1200
|
could be some reserved word, or the `$` in general cannot be used for a key to start with.
|
|
1283
1201
|
|
|
1284
1202
|
You can define your own `valueKey` by passing it in the `wsdl_options` to the createClient call:
|
|
1285
|
-
|
|
1286
1203
|
```javascript
|
|
1287
1204
|
var wsdlOptions = {
|
|
1288
|
-
valueKey:
|
|
1205
|
+
valueKey: 'theVal'
|
|
1289
1206
|
};
|
|
1290
1207
|
|
|
1291
|
-
soap.createClient(
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
function (err, client) {
|
|
1295
|
-
// your code
|
|
1296
|
-
}
|
|
1297
|
-
);
|
|
1208
|
+
soap.createClient(__dirname + '/wsdl/default_namespace.wsdl', wsdlOptions, function (err, client) {
|
|
1209
|
+
// your code
|
|
1210
|
+
});
|
|
1298
1211
|
```
|
|
1299
1212
|
|
|
1300
1213
|
### Overriding the `xml` key
|
|
1301
|
-
|
|
1302
1214
|
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.
|
|
1303
1215
|
|
|
1304
1216
|
For example :
|
|
1305
|
-
|
|
1306
1217
|
```javascript
|
|
1307
1218
|
{
|
|
1308
1219
|
dom: {
|
|
@@ -1321,9 +1232,7 @@ For example :
|
|
|
1321
1232
|
}
|
|
1322
1233
|
};
|
|
1323
1234
|
```
|
|
1324
|
-
|
|
1325
1235
|
could become
|
|
1326
|
-
|
|
1327
1236
|
```xml
|
|
1328
1237
|
<tns:dom>
|
|
1329
1238
|
<tns:nodeone>
|
|
@@ -1340,26 +1249,20 @@ could become
|
|
|
1340
1249
|
```
|
|
1341
1250
|
|
|
1342
1251
|
You can define your own `xmlKey` by passing it in the `wsdl_options` object to the createClient call:
|
|
1343
|
-
|
|
1344
1252
|
```javascript
|
|
1345
1253
|
var wsdlOptions = {
|
|
1346
|
-
xmlKey:
|
|
1254
|
+
xmlKey: 'theXml'
|
|
1347
1255
|
};
|
|
1348
1256
|
|
|
1349
|
-
soap.createClient(
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
function (err, client) {
|
|
1353
|
-
// your code
|
|
1354
|
-
}
|
|
1355
|
-
);
|
|
1257
|
+
soap.createClient(__dirname + '/wsdl/default_namespace.wsdl', wsdlOptions, function (err, client) {
|
|
1258
|
+
// your code
|
|
1259
|
+
});
|
|
1356
1260
|
```
|
|
1357
1261
|
|
|
1358
1262
|
### Overriding the `attributes` key
|
|
1359
|
-
|
|
1360
1263
|
By default, `node-soap` uses `attributes` as the key to define a nodes attributes.
|
|
1361
1264
|
|
|
1362
|
-
```javascript
|
|
1265
|
+
``` javascript
|
|
1363
1266
|
{
|
|
1364
1267
|
parentnode: {
|
|
1365
1268
|
childnode: {
|
|
@@ -1371,45 +1274,37 @@ By default, `node-soap` uses `attributes` as the key to define a nodes attribute
|
|
|
1371
1274
|
}
|
|
1372
1275
|
}
|
|
1373
1276
|
```
|
|
1374
|
-
|
|
1375
1277
|
could become
|
|
1376
|
-
|
|
1377
|
-
```xml
|
|
1278
|
+
``` xml
|
|
1378
1279
|
<parentnode>
|
|
1379
1280
|
<childnode name="childsname">Value</childnode>
|
|
1380
1281
|
</parentnode>
|
|
1381
1282
|
```
|
|
1382
1283
|
|
|
1383
1284
|
However, `attributes` may be a reserved key for some systems that actually want a node called `attributes`
|
|
1384
|
-
|
|
1385
1285
|
```xml
|
|
1386
1286
|
<attributes>
|
|
1387
1287
|
</attributes>
|
|
1388
1288
|
```
|
|
1389
1289
|
|
|
1390
1290
|
You can define your own `attributesKey` by passing it in the `wsdl_options` object to the createClient call:
|
|
1391
|
-
|
|
1392
1291
|
```javascript
|
|
1393
1292
|
var wsdlOptions = {
|
|
1394
|
-
attributesKey:
|
|
1293
|
+
attributesKey: '$attributes'
|
|
1395
1294
|
};
|
|
1396
1295
|
|
|
1397
|
-
soap.createClient(
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
childnode: {
|
|
1404
|
-
$attributes: {
|
|
1405
|
-
name: "childsname",
|
|
1406
|
-
},
|
|
1407
|
-
$value: "Value",
|
|
1296
|
+
soap.createClient(__dirname + '/wsdl/default_namespace.wsdl', wsdlOptions, function (err, client) {
|
|
1297
|
+
client.method({
|
|
1298
|
+
parentnode: {
|
|
1299
|
+
childnode: {
|
|
1300
|
+
$attributes: {
|
|
1301
|
+
name: 'childsname'
|
|
1408
1302
|
},
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
);
|
|
1303
|
+
$value: 'Value'
|
|
1304
|
+
}
|
|
1305
|
+
}
|
|
1306
|
+
});
|
|
1307
|
+
});
|
|
1413
1308
|
```
|
|
1414
1309
|
|
|
1415
1310
|
### Overriding imports relative paths
|
|
@@ -1446,30 +1341,43 @@ soap.createClient('https://127.0.0.1/service.wsdl', options, function(err, clien
|
|
|
1446
1341
|
```
|
|
1447
1342
|
|
|
1448
1343
|
### Specifying the exact namespace definition of the root element
|
|
1449
|
-
|
|
1450
1344
|
In rare cases, you may want to precisely control the namespace definition that is included in the root element.
|
|
1451
1345
|
|
|
1452
1346
|
You can specify the namespace definitions by setting the `overrideRootElement` key in the `wsdlOptions` like so:
|
|
1453
|
-
|
|
1454
1347
|
```javascript
|
|
1455
1348
|
var wsdlOptions = {
|
|
1456
1349
|
overrideRootElement: {
|
|
1457
|
-
namespace:
|
|
1458
|
-
xmlnsAttributes: [
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
},
|
|
1467
|
-
],
|
|
1468
|
-
},
|
|
1350
|
+
namespace: 'xmlns:tns',
|
|
1351
|
+
xmlnsAttributes: [{
|
|
1352
|
+
name: 'xmlns:ns2',
|
|
1353
|
+
value: "http://tempuri.org/"
|
|
1354
|
+
}, {
|
|
1355
|
+
name: 'xmlns:ns3',
|
|
1356
|
+
value: "http://sillypets.com/xsd"
|
|
1357
|
+
}]
|
|
1358
|
+
}
|
|
1469
1359
|
};
|
|
1470
1360
|
```
|
|
1471
1361
|
|
|
1472
|
-
To see it in practice, have a look at the sample files in: [test/request-response-samples/
|
|
1362
|
+
To see it in practice, have a look at the sample files in: [test/request-response-samples/addPets__force_namespaces](https://github.com/vpulim/node-soap/tree/master/test/request-response-samples/addPets__force_namespaces)
|
|
1363
|
+
|
|
1364
|
+
### Overriding element key specification in XML
|
|
1365
|
+
|
|
1366
|
+
In very rare cases ([external implementation isn't matching exactly the WSDL spec?](https://github.com/vpulim/node-soap/pull/1189)),
|
|
1367
|
+
you may want to override element XML keys in requests and/or responses.
|
|
1368
|
+
|
|
1369
|
+
You can specify the key definitions by setting the `overrideElementKey` key in the `wsdlOptions` like so:
|
|
1370
|
+
```javascript
|
|
1371
|
+
var wsdlOptions = {
|
|
1372
|
+
overrideElementKey: {
|
|
1373
|
+
Nom: 'Name',
|
|
1374
|
+
Commande: 'Order',
|
|
1375
|
+
SillyResponse: 'DummyResponse'
|
|
1376
|
+
};
|
|
1377
|
+
};
|
|
1378
|
+
```
|
|
1379
|
+
|
|
1380
|
+
Test sample files covering this are in [test/request-response-samples/Dummy__ref_element_should_have_correct_namespace_with_overrideElementKey](https://github.com/vpulim/node-soap/tree/master/test/request-response-samples/Dummy__ref_element_should_have_correct_namespace_with_overrideElementKey)
|
|
1473
1381
|
|
|
1474
1382
|
### Custom Deserializer
|
|
1475
1383
|
|
|
@@ -1479,7 +1387,6 @@ For example if the soap response contains dates that are not in a format recogni
|
|
|
1479
1387
|
To do so, you can pass a `customDeserializer` object in `options`. The properties of this object are the types that your deserializer handles itself.
|
|
1480
1388
|
|
|
1481
1389
|
Example :
|
|
1482
|
-
|
|
1483
1390
|
```javascript
|
|
1484
1391
|
|
|
1485
1392
|
var wsdlOptions = {
|
|
@@ -1510,60 +1417,53 @@ Example :
|
|
|
1510
1417
|
```
|
|
1511
1418
|
|
|
1512
1419
|
### Changing the tag formats to use self-closing (empty element) tags
|
|
1513
|
-
|
|
1514
1420
|
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.
|
|
1515
1421
|
|
|
1516
1422
|
```javascript
|
|
1517
1423
|
var wsdlOptions = {
|
|
1518
|
-
useEmptyTag: true
|
|
1424
|
+
useEmptyTag: true
|
|
1519
1425
|
};
|
|
1520
1426
|
```
|
|
1521
1427
|
|
|
1522
1428
|
For example: `{ MyTag: { attributes: { MyAttr: 'value' } } }` is:
|
|
1523
1429
|
|
|
1524
|
-
|
|
1525
|
-
|
|
1430
|
+
* **Without useEmptyTag**: `<MyTag MyAttr="value"></MyTag>`
|
|
1431
|
+
* **With useEmptyTag set to true**: `<MyTag MyAttr="value" />`
|
|
1526
1432
|
|
|
1527
1433
|
## Handling "ignored" namespaces
|
|
1528
|
-
|
|
1529
1434
|
If an Element in a `schema` definition depends on an Element which is present in the same namespace, normally the `tns:`
|
|
1530
1435
|
namespace prefix is used to identify this Element. This is not much of a problem as long as you have just one `schema` defined
|
|
1531
1436
|
(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,
|
|
1532
|
-
which was obviously wrong.
|
|
1533
|
-
|
|
1534
|
-
`node-soap` now handles namespace prefixes which shouldn't be resolved (because it's not necessary) as so called `ignoredNamespaces`
|
|
1535
|
-
which default to an Array of 3 Strings (`['tns', 'targetNamespace', 'typedNamespace']`).
|
|
1536
|
-
|
|
1537
|
-
If this is not sufficient for your purpose you can easily add more namespace prefixes to this Array, or override it in its entirety
|
|
1538
|
-
by passing an `ignoredNamespaces` object within the `options` you pass in `soap.createClient()` method.
|
|
1539
|
-
|
|
1540
|
-
A simple `ignoredNamespaces` object, which only adds certain namespaces could look like this:
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
}
|
|
1561
|
-
```
|
|
1562
|
-
|
|
1563
|
-
This would override the default `ignoredNamespaces` of the `WSDL` processor to `['namespaceToIgnore', 'someOtherNamespace']`. (This shouldn't be necessary, anyways).
|
|
1437
|
+
which was obviously wrong.
|
|
1438
|
+
|
|
1439
|
+
`node-soap` now handles namespace prefixes which shouldn't be resolved (because it's not necessary) as so called `ignoredNamespaces`
|
|
1440
|
+
which default to an Array of 3 Strings (`['tns', 'targetNamespace', 'typedNamespace']`).
|
|
1441
|
+
|
|
1442
|
+
If this is not sufficient for your purpose you can easily add more namespace prefixes to this Array, or override it in its entirety
|
|
1443
|
+
by passing an `ignoredNamespaces` object within the `options` you pass in `soap.createClient()` method.
|
|
1444
|
+
|
|
1445
|
+
A simple `ignoredNamespaces` object, which only adds certain namespaces could look like this:
|
|
1446
|
+
```
|
|
1447
|
+
var options = {
|
|
1448
|
+
ignoredNamespaces: {
|
|
1449
|
+
namespaces: ['namespaceToIgnore', 'someOtherNamespace']
|
|
1450
|
+
}
|
|
1451
|
+
}
|
|
1452
|
+
```
|
|
1453
|
+
This would extend the `ignoredNamespaces` of the `WSDL` processor to `['tns', 'targetNamespace', 'typedNamespace', 'namespaceToIgnore', 'someOtherNamespace']`.
|
|
1454
|
+
|
|
1455
|
+
If you want to override the default ignored namespaces you would simply pass the following `ignoredNamespaces` object within the `options`:
|
|
1456
|
+
```
|
|
1457
|
+
var options = {
|
|
1458
|
+
ignoredNamespaces: {
|
|
1459
|
+
namespaces: ['namespaceToIgnore', 'someOtherNamespace'],
|
|
1460
|
+
override: true
|
|
1461
|
+
}
|
|
1462
|
+
}
|
|
1463
|
+
```
|
|
1464
|
+
This would override the default `ignoredNamespaces` of the `WSDL` processor to `['namespaceToIgnore', 'someOtherNamespace']`. (This shouldn't be necessary, anyways).
|
|
1564
1465
|
|
|
1565
1466
|
## Handling "ignoreBaseNameSpaces" attribute
|
|
1566
|
-
|
|
1567
1467
|
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"
|
|
1568
1468
|
but the request need only: <sendJob> set in the tree structure, you need to set the ignoreBaseNameSpaces to true. This is set because in a lot of workaround the wsdl structure is not correctly
|
|
1569
1469
|
set or the webservice bring errors.
|
|
@@ -1572,7 +1472,6 @@ By default the attribute is set to true.
|
|
|
1572
1472
|
An example to use:
|
|
1573
1473
|
|
|
1574
1474
|
A simple `ignoredNamespaces` object, which only adds certain namespaces could look like this:
|
|
1575
|
-
|
|
1576
1475
|
```
|
|
1577
1476
|
var options = {
|
|
1578
1477
|
ignoredNamespaces: true
|
|
@@ -1581,7 +1480,7 @@ ignoredNamespaces: true
|
|
|
1581
1480
|
|
|
1582
1481
|
## soap-stub
|
|
1583
1482
|
|
|
1584
|
-
Unit testing services that use soap clients can be very cumbersome.
|
|
1483
|
+
Unit testing services that use soap clients can be very cumbersome. In order to get
|
|
1585
1484
|
around this you can use `soap-stub` in conjunction with `sinon` to stub soap with
|
|
1586
1485
|
your clients.
|
|
1587
1486
|
|
|
@@ -1629,20 +1528,23 @@ describe('myService', function() {
|
|
|
1629
1528
|
});
|
|
1630
1529
|
```
|
|
1631
1530
|
|
|
1531
|
+
|
|
1632
1532
|
## Contributors
|
|
1633
1533
|
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
|
|
1534
|
+
* Author: [Vinay Pulim](https://github.com/vpulim)
|
|
1535
|
+
* Active maintainers:
|
|
1536
|
+
- [Vasily Martynov](https://github.com/w666)
|
|
1537
|
+
* Previous maintainers (not active for a long time):
|
|
1538
|
+
- [Joe Spencer](https://github.com/jsdevel)
|
|
1539
|
+
- [Heinz Romirer](https://github.com/herom)
|
|
1540
|
+
* [All Contributors](https://github.com/vpulim/node-soap/graphs/contributors)
|
|
1641
1541
|
|
|
1642
1542
|
[downloads-image]: http://img.shields.io/npm/dm/soap.svg
|
|
1643
1543
|
[npm-url]: https://npmjs.org/package/soap
|
|
1644
1544
|
[npm-image]: http://img.shields.io/npm/v/soap.svg
|
|
1545
|
+
|
|
1645
1546
|
[coveralls-url]: https://coveralls.io/r/vpulim/node-soap
|
|
1646
1547
|
[coveralls-image]: http://img.shields.io/coveralls/vpulim/node-soap/master.svg
|
|
1548
|
+
|
|
1647
1549
|
[buy-me-a-coffee-url]: https://coff.ee/vasily.m
|
|
1648
1550
|
[buy-me-a-coffee-image]: https://www.buymeacoffee.com/assets/img/custom_images/orange_img.png
|