This module lets you connect to web services using SOAP, in pure javascript, using node or browser.
This module is branched from node module "[email protected]". Specific changes are:
- soap server removed
- use [email protected] as xml parser, because its pure javascript
- use jQuery $.ajax for http request, to support browser
- removed all other dependencies on nodejs modules
Features (copied from [email protected] Readme.md):
- Very simple API
- Handles both RPC and Document schema types
- Supports multiRef SOAP messages (thanks to @kaven276)
- Support for both synchronous and asynchronous method handlers
- WS-Security (currently only UsernameToken and PasswordText encoding is supported)
Install with npm:
npm install tinysoap
Embed jquery script first, for example:
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
Then embed the file "./tinysoap-browser-min.js"
<script src="tinysoap-browser-min.js"></script>
Then you write code such as:
// in global scope:
this.tinysoap.createClient("/ACMEWebService?WSDL", function(err, client) {
if (!err)
console.log(client); // all methods are stored in client
});
JSONP is not currently supported, but should be very simple to add...
var soap = require('soap');
var url = 'http://example.com/wsdl?wsdl';
var args = {name: 'value'};
soap.createClient(url, function(err, client) {
client.MyFunction(args, function(err, result) {
console.log(result);
});
});
An instance of Client is passed to the soap.createClient callback. It is used to execute methods on the soap service.
client.describe() // returns
{
MyService: {
MyPort: {
MyFunction: {
input: {
name: 'string'
}
}
}
}
}
client.setSecurity(new WSSecurity('username', 'password'))
client.MyFunction({name: 'value'}, function(err, result) {
// result is a javascript object
})
client.MyService.MyPort.MyFunction({name: 'value'}, function(err, result) {
// result is a javascript object
})
WSSecurity implements WS-Security. UsernameToken and PasswordText/PasswordDigest is supported. An instance of WSSecurity is passed to Client.setSecurity.
new WSSecurity(username, password, passwordType)
//'PasswordDigest' or 'PasswordText' default is PasswordText