Fork of soap. Supports xml attributes and soap faults.
npm install soap-bubblesThe original soap library did not handle XML attributes, so we've switched to using the xml2js library for xml->json and json->xml conversions.
For example, by using xml2js:
`` javascript`
var obj = {
"wd:Worker_Reference": {
"wd:Employee_Reference": {
"wd:Integration_ID_Reference": {
"wd:ID": {
"@": {
"wd:System_ID": "WD-EMPLID"
},
"#": "employee_id"
}
}
}
}
};
Becomes:
` xml`
And likewise in reverse.
As a consequence of using xml2js, which does not support stripping xmlns aliases during conversion, XML converted to a JavaScript object will still have the namespace aliases on the hash keys.
This module lets you connect to web services using SOAP. It also provides a server that allows you to run your own SOAP services.
Features:
* 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 soapModule
` javascript`
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);
});
});
` javascript
var myService = {
MyService: {
MyPort: {
MyFunction: function(args) {
return {
name: args.name
};
}
// This is how to define an asynchronous function.
MyAsyncFunction: function(args, callback) {
// do some work
callback({
name: args.name
})
}
}
}
}
var xml = require('fs').readFileSync('myservice.wsdl', 'utf8'),
server = http.createServer(function(request,response) {
response.end("404: Not Found: "+request.url)
});
server.listen(8000);
soap.listen(server, '/wsdl', myService, xml);
`
If the log method is defined it will be called with 'received' and 'replied'
along with data.
` javascript`
server = soap.listen(...)
server.log = function(type, data) {
// type is 'received' or 'replied'
};
If server.authenticate is not defined no authentation will take place.
` javascript`
server = soap.listen(...)
server.authenticate = function(security) {
var created, nonce, password, user, token;
token = security.UsernameToken, user = token.Username,
password = token.Password, nonce = token.Nonce, created = token.Created;
return user === 'user' && password === soap.passwordDigest(nonce, created, 'password');
};
This is called prior to soap service method
If the method is defined and returns false the incoming connection is
terminated.
` javascript`
server = soap.listen(...)
server.authorizeConnection = function(req) {
return true; // or false
};
An instance of Client is passed to the soap.createClient callback. It is used to execute methods on the soap service.
` javascript`
client.describe() // returns
{
MyService: {
MyPort: {
MyFunction: {
input: {
name: 'string'
}
}
}
}
}
` javascript`
client.setSecurity(new WSSecurity('username', 'password'))
` javascript`
client.MyFunction({name: 'value'}, function(err, result) {
// result is a javascript object
})$3
` javascript`
client.MyService.MyPort.MyFunction({name: 'value'}, function(err, result) {
// result is a javascript object
})$3
#### Options
- soapHeader Object({rootName: {name: "value"}}) or strict xml-string
##### Optional parameters when first arg is object :
- name Unknown parameter (it could just a empty string)namespace
- prefix of xml namespacexmlns
- URI
WSSecurity implements WS-Security. UsernameToken and PasswordText/PasswordDigest is supported. An instance of WSSecurity is passed to Client.setSecurity.
` javascript``
new WSSecurity(username, password, passwordType)
//'PasswordDigest' or 'PasswordText' default is PasswordText