Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add envelopeSoapUrl option #1239

Merged
merged 3 commits into from
Jun 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ export class Client extends EventEmitter {
this.overridePromiseSuffix = options.overridePromiseSuffix || 'Async';
this.wsdl.options.attributesKey = options.attributesKey || 'attributes';
this.wsdl.options.envelopeKey = options.envelopeKey || 'soap';
this.wsdl.options.envelopeSoapUrl = options.envelopeSoapUrl || 'http://schemas.xmlsoap.org/soap/envelope/';
this.wsdl.options.preserveWhitespace = !!options.preserveWhitespace;
const igNs = options.ignoredNamespaces;
if (igNs !== undefined && typeof igNs === 'object') {
Expand Down Expand Up @@ -300,6 +301,7 @@ export class Client extends EventEmitter {
const style = method.style;
const defs = this.wsdl.definitions;
const envelopeKey = this.wsdl.options.envelopeKey;
const envelopeSoapUrl = this.wsdl.options.envelopeSoapUrl;
const ns: string = defs.$targetNamespace;
let encoding = '';
let message = '';
Expand All @@ -309,7 +311,7 @@ export class Client extends EventEmitter {
let headers: any = {
'Content-Type': 'text/xml; charset=utf-8',
};
let xmlnsSoap = 'xmlns:' + envelopeKey + '="http://schemas.xmlsoap.org/soap/envelope/"';
let xmlnsSoap = 'xmlns:' + envelopeKey + '="' + envelopeSoapUrl + '"';

const finish = (obj, body, response) => {
let result;
Expand Down
2 changes: 2 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ export interface IOptions extends IWsdlBaseOptions {
endpoint?: string;
/** set specific key instead of <pre><soap:Body></soap:Body></pre>. */
envelopeKey?: string;
/** set specific SOAP Schema Url; will not be used with forceSoap12Headers option */
envelopeSoapUrl?: string;
/** provide your own http client that implements request(rurl, data, callback, exheaders, exoptions) */
httpClient?: IHttpClient;
/** override the request module. */
Expand Down
12 changes: 12 additions & 0 deletions test/client-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1470,6 +1470,18 @@ var fs = require('fs'),
});
});

it('should allow customization of envelope Soap Url', function (done) {
soap.createClient(__dirname + '/wsdl/default_namespace.wsdl', Object.assign({ envelopeSoapUrl: 'http://example.com/v1' }, meta.options), function (err, client) {
assert.ok(client);
assert.ifError(err);

client.MyOperation({}, function (err, result) {
assert.notEqual(client.lastRequest.indexOf('xmlns:soap=\"http://example.com/v1\"'), -1);
done();
});
});
});

it('should add soap headers', function (done) {
soap.createClientAsync(__dirname + '/wsdl/default_namespace.wsdl', meta.options)
.then(function (client) {
Expand Down
Loading