官方文档:https://www.npmjs.com/package/soap
Install
npm install soap
方法
- soap.createClient(url[, options], callback)
var soap = require('soap');
var url = 'http://example.com/wsdl?wsdl';
var args = {name: 'value'};
soap.createClient(url, function(err, client) {
client.***(args, function(err, result) {
console.log(result);
});
});
- soap.createClientAsync(url[, options])
var soap = require('soap');
var url = 'http://example.com/wsdl?wsdl';
var args = {name: 'value'};
soap.createClientAsync(url).then((client) => {
return client.['***' + 'Async'](args);
}).then((result) => {
console.log(result);
});
options参数(有以下几个):
- endpoint: to override the SOAP service's host specified in the
.wsdl
file.(不懂) - envelopeKey: to set specific key instead of
<pre><soap:Body></soap:Body></pre>
.(不懂) - preserveWhitespace: 保留text and cdata前后的空格
- escapeXML: 将SOAP信息中特殊的XML符号escape编码处理,例如
&
,>
,<
等,属性值默认为true - suppressStack: suppress the full stack trace for error messages.
- returnFault: 对于错误请求,返回一个无效的XMLSOAP,默认为false
- forceSoap12Headers: 将消息头强制设置成SOAP1.2
- httpClient: to provide your own http client that implements
request(rurl, data, callback, exheaders, exoptions)
.(提供你自己的http请求。。。不懂) - request: 重写request模块.
- wsdl_headers: 在WSDL请求中自定义发送的HTTP头.
- wsdl_options: 在WSDL请求中为request模块自定义选项.
- disableCache: 不缓存WSDL文件,每次都重新请求.
- overridePromiseSuffix: 如果你的WSDL操作包含Async后缀,你需要去重写一个特定的后缀,选项默认为
Async
- normalizeNames: if your wsdl operations contains names with non identifier characters (
[^a-z$_0-9]
), replace them with_
. Note: if using this option, clients using wsdls with two operations likesoap:method
andsoap-method
will be overwritten. Then, use bracket notation instead (client['soap:method']()
).(不懂) - namespaceArrayElements: provides support for nonstandard array semantics. If true, JSON arrays of the form
{list: [{elem: 1}, {elem: 2}]}
are marshalled into xml as<list><elem>1</elem></list> <list><elem>2</elem></list>
. If false, marshalls into<list> <elem>1</elem> <elem>2</elem> </list>
. Default:true
.(不懂)
!!!0.10.X以上版本的node,要增加这个参数{connection: 'keep-alive'}避免截断了过长的请求