diff --git a/Readme.md b/Readme.md index 912c5697..420cbc37 100644 --- a/Readme.md +++ b/Readme.md @@ -229,6 +229,7 @@ Note: for versions of node >0.10.X, you may need to specify `{connection: 'keep- - `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`) + - `envelopeKey` (*string*): Set a custom envelope key. (**Default:** `'soap'`) - `services` (*Object*) - `wsdl` (*string*): An XML string that defines the service. - `callback` (*Function*): A function to run after the server has been initialized. diff --git a/src/server.ts b/src/server.ts index da04e6a1..aeb74257 100644 --- a/src/server.ts +++ b/src/server.ts @@ -199,6 +199,7 @@ export class Server extends EventEmitter { this.wsdl.options.attributesKey = options.attributesKey || 'attributes'; this.onewayOptions.statusCode = this.onewayOptions.responseCode || 200; this.onewayOptions.emptyBody = !!this.onewayOptions.emptyBody; + this.wsdl.options.envelopeKey = options.envelopeKey || 'soap'; } private _processRequestXml(req: Request, res: Response, xml) { @@ -599,13 +600,14 @@ export class Server extends EventEmitter { const ns = defs.$targetNamespace; const encoding = ''; const alias = findPrefix(defs.xmlns, ns); + const envelopeKey = this.wsdl.options.envelopeKey; const envelopeDefinition = this.wsdl.options.forceSoap12Headers ? 'http://www.w3.org/2003/05/soap-envelope' : 'http://schemas.xmlsoap.org/soap/envelope/'; let xml = '' + - ''; @@ -627,12 +629,10 @@ export class Server extends EventEmitter { } if (headers !== '') { - xml += '' + headers + ''; + xml += '<' + envelopeKey + ':Header>' + headers + ''; } - - xml += body ? '' + body + '' : ''; - - xml += ''; + xml += body ? '<' + envelopeKey + ':Body>' + body + '' : '<' + envelopeKey + ':Body/>'; + xml += ''; return xml; } diff --git a/src/types.ts b/src/types.ts index 4e4f9819..59d8c9dc 100644 --- a/src/types.ts +++ b/src/types.ts @@ -156,6 +156,7 @@ export interface IServerOptions extends IWsdlBaseOptions { oneWay?: IOneWayOptions; /** A boolean for controlling chunked transfer encoding in response. Some client (such as Windows 10's MDM enrollment SOAP client) is sensitive to transfer-encoding mode and can't accept chunked response. This option let user disable chunked transfer encoding for such a client. Default to true for backward compatibility. */ enableChunkedEncoding?: boolean; + envelopeKey?: string; } export interface IMTOMAttachments { diff --git a/test/server-options-test.js b/test/server-options-test.js index cbbb6ca9..de86d124 100644 --- a/test/server-options-test.js +++ b/test/server-options-test.js @@ -625,4 +625,72 @@ describe('SOAP Server with Options', function () { }); }); + it('should return soapenv as envelope key when it is set to soapenv', function (done) { + test.server.listen(15099, null, null, function () { + test.soapServer = soap.listen(test.server, { + path: '/stockquote', + services: test.service, + xml: test.wsdl, + uri: __dirname + '/wsdl/strict/', + envelopeKey: 'soapenv' + }, test.service, test.wsdl); + test.baseUrl = 'http://' + test.server.address().address + ":" + test.server.address().port; + + //windows return 0.0.0.0 as address and that is not + //valid to use in a request + if (test.server.address().address === '0.0.0.0' || test.server.address().address === '::') { + test.baseUrl = 'http://127.0.0.1:' + test.server.address().port; + } + // console.log(test.baseUrl); + axios.post( + test.baseUrl + '/stockquote', + '' + + ' ' + + ' ' + + '' + ).then(res => { + assert.ok(res.data.indexOf('soapenv:Envelope') > -1); + done(); + }).catch(err => { + throw err; + }); + }); + }); + + it('should return soap as envelope key by default', function (done) { + test.server.listen(15099, null, null, function () { + test.soapServer = soap.listen(test.server, { + path: '/stockquote', + services: test.service, + xml: test.wsdl, + uri: __dirname + '/wsdl/strict/', + forceSoap12Headers: true + }, test.service, test.wsdl); + test.baseUrl = 'http://' + test.server.address().address + ":" + test.server.address().port; + + //windows return 0.0.0.0 as address and that is not + //valid to use in a request + if (test.server.address().address === '0.0.0.0' || test.server.address().address === '::') { + test.baseUrl = 'http://127.0.0.1:' + test.server.address().port; + } + // console.log(test.baseUrl); + axios.post( + test.baseUrl + '/stockquote', + '' + + ' ' + + ' ' + + '' + ).then(res => { + assert.ok(res.data.indexOf('soap:Envelope') > -1); + done(); + }).catch(err => { + throw err; + }); + }); + }); + });