帮酷LOGO
0 0 评论
  • 显示原文与译文双语对照的内容
文章标签:SOAP  SOA  
A simple to use SoapClient for Node.js

  • 源代码名称:easysoap
  • 源代码网址:http://www.github.com/moszeed/easysoap
  • easysoap源代码文档
  • easysoap源代码下载
  • Git URL:
    git://www.github.com/moszeed/easysoap.git
  • Git Clone代码到本地:
    git clone http://www.github.com/moszeed/easysoap
  • Subversion代码到本地:
    $ svn co --depth empty http://www.github.com/moszeed/easysoap
    Checked out revision 1.
    $ cd repo
    $ svn up trunk
    
  • EasySoap

    easysoap 是用于 Node.js.的WSDL SoapClient

    :如何获取

    安装使用 npm npm i easysoap

    用法

    获取soapclient实例

    
    const EasySoap = require('easysoap');
    
    
    const soapClient = EasySoap(params, opts);
    
    
    
    

    params params soapOptions响应实例。

    可能的参数数据
    
    {
    
    
     host : 'www.example.com',
    
    
     path : '/soap/path',
    
    
     wsdl : '/wsdl/path',
    
    
     headers : Array or Object,
    
    
     rejectUnauthorized : true/false
    
    
    }
    
    
    
    

    soapOptions

    
    {
    
    
     secure : true/false//is https or http
    
    
    }
    
    
    
    
    在创建soapclient实例后,以下方法可用:easysoap call调用

    英镑参数 callParams callResponseObject

    getRequestXml

    英镑 params callParams 响应( 字符串)

    callParams

    
    {
    
    
     method :"sampleMethodName",
    
    
     attributes: Object of custom tag attributes for given params,
    
    
     params : Object/Array of params
    
    
    }
    
    
    
    
    getXmlDataAsJson

    params xml response response响应 json

    getAllFunctions

    响应函数名称( array )

    getMethodParamsByName

    英镑参数( 字符串) 响应 methodParams ( 对象)

    示例

    
    (() => {
    
    
     'use strict';
    
    
     const EasySoap = require('easysoap');
    
    
    
    //define soap params
    
    
     const params = {
    
    
     host: 'www.sample.com',
    
    
     path: '/path/soap/',
    
    
     wsdl: '/path/wsdl/',
    
    
    
    //set soap headers (optional)
    
    
     headers: [{
    
    
     'name' : 'item_name',
    
    
     'value' : 'item_value',
    
    
     'namespace': 'item_namespace'
    
    
     }]
    
    
     }
    
    
    
    /*
    
    
     * create the client
    
    
     */
    
    
     var soapClient = EasySoap(params);
    
    
    
    /*
    
    
     * get all available functions
    
    
     */
    
    
    soapClient.getAllFunctions()
    
    
    . then((functionArray) => { console.log(functionArray); })
    
    
    . catch((err) => { throw new Error(err); });
    
    
    
    /*
    
    
     * get the method params by given methodName
    
    
     */
    
    
    soapClient.getMethodParamsByName('methodName')
    
    
    . then((methodParams) => {
    
    
     console.log(methodParams.request);
    
    
     console.log(methodParams.response);
    
    
     })
    
    
    . catch((err) => { throw new Error(err); });
    
    
    
    /*
    
    
     * call soap method
    
    
     */
    
    
    soapClient.call({
    
    
     method : 'methodName',
    
    
     attributes: {
    
    
     xmlns: 'http://www.sample.com'
    
    
     },
    
    
     params: {
    
    
     testParam: 1,
    
    
     testParam: [2, 3],
    
    
     testParam: {
    
    
     '_value' : 4,
    
    
     '_attributes': {
    
    
     'xmlns1': 'http://www.sample.com/other'
    
    
     }
    
    
     }
    
    
     }
    
    
    })
    
    
    .then((callResponse) => {
    
    
     console.log(callResponse.data);//response data as json
    
    
     console.log(callResponse.body);//response body
    
    
     console.log(callResponse.header);//response header
    
    
    })
    
    
    .catch((err) => { throw new Error(err); });
    
    
    
    


    文章标签:SOAP  SOA  

    Copyright © 2011 HelpLib All rights reserved.    知识分享协议 京ICP备05059198号-3  |  如果智培  |  酷兔英语