返回> 网站首页 

WSDL to Javascript

yoours2018-02-27 17:01:39 阅读 3498

简介一边听听音乐,一边写写文章。

一、转换工具
wsdl2js 下载地址:http://cxf.apache.org/docs/wsdl-to-javascript.html

二、生成js文件
例如: 文件夹apache-cxf-3.2.2\bin\下
 idl2wsdl.bat  wsdl2js hello_world12.wsdl
自动生成js文件

三、开发使用
包含脚本 cxf-utils.js 和生成的js文件,例如Middle.js
html页面文件如下:

<html>
<head>
    <script type="text/javascript" src="cxf-utils.js"></script>
    <script type="text/javascript" src="Middle.js"></script>
</head>
<body> 
<script type="text/javascript">
    function succStartCheck(obj)
    {
        alert("StartCheck:" + obj.getResult());
    }

    function errStartCheck(obj)
    {
        alert("StartCheck:" + obj.getResult());
    }

    function succStopCheck(obj) {
        alert("StopCheck:" + obj.getResult());
    }

    function errStopCheck(obj) {
        alert("StopCheck:" + obj.getResult());
    }

    localhost_ns__Middle_wsdl_MiddlePortType_localhost_ns__Middle_wsdl_Middle();

    function startcheck()
    {
        localhost_ns__Middle_wsdl_MiddlePortType_localhost_ns__Middle_wsdl_Middle.prototype.startCheck(succStartCheck, errStartCheck, "{\"mNo\" :\"1\", \"rNo\" :\"2\" , \"tt\" :\"3\"}");
    }

    function stopcheck() {
        localhost_ns__Middle_wsdl_MiddlePortType_localhost_ns__Middle_wsdl_Middle.prototype.stopCheck(succStopCheck, errStopCheck, "{\"mNo\" :\"001\", \"rNo\" :\"002\"}");
    }
</script>

    <button onclick="javascript: startcheck()">StartCheck</button>
    <button onclick="javascript: stopcheck()">StopCheck</button>
</body>
</html>

生成的js文件修改:
1. 必须将this.url改为url,否则获取不到url变量内容,例如:
function localhost_ns__Middle_wsdl_startCheck_op(successCallback, errorCallback, str) {
    this.client = new CxfApacheOrgClient(this.jsutils);
    var xml = null;
    var args = new Array(1);
    args[0] = str;
    xml = this.startCheckRequest_serializeInput(this.jsutils, args);
    this.client.user_onsuccess = successCallback;
    this.client.user_onerror = errorCallback;
    var closureThis = this;
    this.client.onsuccess = function(client, responseXml) { closureThis.startCheck_onsuccess(client, responseXml); };
    this.client.onerror = function(client) { closureThis.startCheck_onerror(client); };
    var requestHeaders = [];
    requestHeaders['SOAPAction'] = '';
    this.jsutils.trace('synchronous = ' + this.synchronous);
    this.client.request(url, xml, null, this.synchronous, requestHeaders);
}

2. 修改url地址,例如
function localhost_ns__Middle_wsdl_MiddlePortType_localhost_ns__Middle_wsdl_Middle () {
  this.url = 'http://localhost:8000/ns__Middle.cgi';
}
微信小程序扫码登陆

文章评论

3498人参与,0条评论