Skip to content
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
1 change: 0 additions & 1 deletion src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,6 @@ export class Client extends EventEmitter {
}
});
}

callback(null, result, body, obj.Header, xml, response.mtomResponseAttachments);
};

Expand Down
32 changes: 24 additions & 8 deletions src/wsdl/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -290,16 +290,32 @@ export class WSDL {
// Look up the appropriate message as given in the portType's operations
const portTypes = this.definitions.portTypes;
const portTypeNames = Object.keys(portTypes);
// Currently this supports only one portType definition.
const portType = portTypes[portTypeNames[0]];
if (isInput) {
name = portType.methods[name].input.$name;
} else {
name = portType.methods[name].output.$name;

for (const portTypeName of portTypeNames) {
const portType = portTypes[portTypeName];
const method = portType.methods[name];

if (!method) {
continue;
}

try {
if (isInput) {
name = portType.methods[name].input.$name;
} else {
name = portType.methods[name].output.$name;
}
message = this.definitions.messages[name];
break;
} catch {
throw new Error(`Failed to lookup message ${name} in methods`);
}
}
if (!message) {
throw new Error(`Could not find message ${name}`);
}
message = this.definitions.messages[name];
// 'cache' this alias to speed future lookups
this.definitions.messages[originalName] = this.definitions.messages[name];
this.definitions.messages[originalName] = message;
} catch (e) {
if (this.options.returnFault) {
p.onerror(e);
Expand Down
21 changes: 16 additions & 5 deletions test/server-options-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -306,9 +306,14 @@ describe('SOAP Server with Options', function () {
// should not go this path, will fail by timeout
})
.catch((err) => {
assert.equal(err.response.status, 500);
assert.ok(err.response.data.indexOf('\n at') !== -1);
done();
try {
assert.equal(err.response.status, 500);
assert.notStrictEqual(err.response.data.indexOf('\n at'), -1);
done();
} catch (assertErr) {
done(assertErr);
throw assertErr;
}
});
});
});
Expand Down Expand Up @@ -423,8 +428,14 @@ describe('SOAP Server with Options', function () {
// should not go this path, will fail by timeout
})
.catch((err) => {
assert.equal(err.response.status, 500);
assert.ok(err.response.data.match(/<faultcode>.*<\/faultcode>/g), 'Invalid XML');
try {
assert.equal(err.response.status, 500);
assert.ok(err.response.data.match(/<faultcode>.*<\/faultcode>/g), 500);
assert.ok(err.response.data.match(/<faultstring>.*<\/faultstring>/g), 'Invalid XML');
} catch (assertError) {
done(assertError);
throw assertError;
}
done();
});
});
Expand Down
79 changes: 79 additions & 0 deletions test/server-service-bind-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
const soap = require('..');
const http = require('http');
const fs = require('fs');
const path = require('path');
const assert = require('assert');
const { deepEqual } = require('should');

const wsdl = fs.readFileSync(__dirname + '/wsdl/multi-service.wsdl', 'utf-8');

describe('SOAP Multi Service Binding', function () {
let server;

const serviceImpl = {
Hello_Service: {
Hello_Port: {
sayHello: function (args) {
return {
greeting: args.firstName,
};
},
},
},
Bye_Service: {
Bye_Port: {
sayBye: function (args) {
return {
bye: args.firstName,
};
},
},
Another_Bye_Port: {
sayAnotherBye: function (args) {
return {
another_bye: args.firstName,
};
},
},
},
};

this.beforeAll(async function () {
server = http.createServer(function (req, res) {
res.writeHead(200, { 'Content-Type': 'text/plain' });
res.write('Hello');
res.end();
});

server.listen(8001, function () {
soap.listen(server, '/SayHello', serviceImpl, wsdl);
soap.listen(server, '/SayBye', serviceImpl, wsdl);
soap.listen(server, '/SayAnotherBye', serviceImpl, wsdl);
});
});

this.afterAll(function () {
server.close();
});

it('should resolve hello service binding in multi service WSDL', async function () {
const client = await soap.createClientAsync(wsdl);
assert.ok(client);
const response = await client.sayHelloAsync({ firstName: 'Bob' });
deepEqual(response[0], { greeting: 'Bob' });
});

it('should resolve bye service binding in multi service WSDL', async function () {
const client = await soap.createClientAsync(wsdl);
assert.ok(client);
const response = await client.sayByeAsync({ firstName: 'Bob' });
deepEqual(response[0], { bye: 'Bob' });
});

it('should resolve bye service with second binding in multi service WSDL', async function () {
const client = await soap.createClientAsync(wsdl);
assert.ok(client);
const response = await client.sayAnotherByeAsync({ firstName: 'Bob' });
deepEqual(response[0], { another_bye: 'Bob' });
});
});
106 changes: 106 additions & 0 deletions test/wsdl/multi-service.wsdl
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
<?xml version="1.0" encoding="UTF-8"?>
<definitions name="HelloService"
targetNamespace="http://www.examples.com/wsdl/HelloService.wsdl"
xmlns="http://schemas.xmlsoap.org/wsdl/"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:tns="http://www.examples.com/wsdl/HelloService.wsdl"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">

<message name="SayHelloRequest">
<part name="firstName" type="xsd:string" />
</message>
<message name="SayHelloResponse">
<part name="greeting" type="xsd:string" />
</message>

<message name="SayByeRequest">
<part name="firstName" type="xsd:string" />
</message>
<message name="SayByeResponse">
<part name="bye" type="xsd:string" />
</message>

<message name="SayAnotherByeRequest">
<part name="firstName" type="xsd:string" />
</message>
<message name="SayAnotherByeResponse">
<part name="another_bye" type="xsd:string" />
</message>

<portType name="Another_Bye_PortType">
<operation name="sayAnotherBye">
<input message="tns:SayAnotherByeRequest" />
<output message="tns:SayAnotherByeResponse" />
</operation>
</portType>
<portType name="Bye_PortType">
<operation name="sayBye">
<input message="tns:SayByeRequest" />
<output message="tns:SayByeResponse" />
</operation>
</portType>
<portType name="Hello_PortType">
<operation name="sayHello">
<input message="tns:SayHelloRequest" />
<output message="tns:SayHelloResponse" />
</operation>
</portType>

<binding name="Hello_Binding" type="tns:Hello_PortType">
<soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http" />
<operation name="sayHello">
<soap:operation soapAction="sayHello" />
<input>
<soap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
namespace="urn:examples:helloservice" use="encoded" />
</input>
<output>
<soap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
namespace="urn:examples:helloservice" use="encoded" />
</output>
</operation>
</binding>
<binding name="Bye_Binding" type="tns:Bye_PortType">
<soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http" />
<operation name="sayBye">
<soap:operation soapAction="sayBye" />
<input>
<soap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
namespace="urn:examples:byeservice" use="encoded" />
</input>
<output>
<soap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
namespace="urn:examples:byeservice" use="encoded" />
</output>
</operation>
</binding>
<binding name="Another_Bye_Binding" type="tns:Another_Bye_PortType">
<soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http" />
<operation name="sayAnotherBye">
<soap:operation soapAction="sayAnotherBye" />
<input>
<soap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
namespace="urn:examples:byeservice" use="encoded" />
</input>
<output>
<soap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
namespace="urn:examples:byeservice" use="encoded" />
</output>
</operation>
</binding>
<service name="Hello_Service">
<documentation>WSDL File for HelloService</documentation>
<port binding="tns:Hello_Binding" name="Hello_Port">
<soap:address location="http://localhost:8001/SayHello/" />
</port>
</service>
<service name="Bye_Service">
<documentation>WSDL File for ByeService</documentation>
<port binding="tns:Bye_Binding" name="Bye_Port">
<soap:address location="http://localhost:8001/SayBye/" />
</port>
<port binding="tns:Another_Bye_Binding" name="Another_Bye_Port">
<soap:address location="http://localhost:8001/SayAnotherBye/" />
</port>
</service>
</definitions>