基于Node.js实现的SOAP客户端和服务器:Node-SOAP

jopen 10年前

Node-SOAP 是基于 Node.js 的 SOAP 客户端和服务器。

该模块可以让你使用SOAP连接到Web服务。它还提供了一个服务器,它允许你运行你自己的SOAP服务。

特性

  • 非常简单的 API

  • 可以处理 RPC 和 Document schema 类型

  • 支持 multiRef SOAP 信息 (thanks to @kaven276)

  • 支持同步和异步方法处理器

  • WS-Security (当前只支持 UsernameToken 和 PasswordText 编码)

Module

soap.createClient(url[, options], callback) - create a new SOAP client from a WSDL url. Also supports a local filesystem path.

  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);        });    });

Within the options object you may provide an endpoint property in case you want to override the SOAP service's host specified in the .wsdl file.

soap.listen(server, path, services, wsdl) - create a new SOAP server that listens on path and provides services.

wsdl is an xml string that defines the service.

  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);

项目主页:http://www.open-open.com/lib/view/home/1410249329711