• FMS2 WebService 功能扩展 - [FMS]

    2007-10-20

    版权声明:转载时请以超链接形式标明文章原始出处和作者信息及本声明
    http://25swf.blogbus.com/logs/10383219.html

    代码文件如下 

    trace("WS ver 0.1 is load")
    load ("webservices/WebServices.asc")
    /****************************************************
    *  FN:WS.as Coder:25swf CreateDate:2007-7-19
    * 扩展FMS自带的WebService类,增加以下方法或功能
    * 修改记录

    ****************************************************/

    var WS = function(wsdlLocation, logObj, proxyURI, endpointProxyURI, serviceName, portName)
    {
     this._myws = new WebService(wsdlLocation, logObj, proxyURI, endpointProxyURI, serviceName, portName)
     //为myws符加parent
     this._myws.parent = this;
     //重实现WebService方法调用,更多信息可以参考WebService的实现方式
     this.__resolve = function(methodName)
        {
      return function()
            {
       var args = new Array();
       for (var i=0; i<arguments.length; i++)
       {
        args[i] = arguments[i];
       }
                args.unshift(methodName);
       var callback = this._myws.stub.invokeOperation.apply(this._myws.stub, args);
       callback.callcount = 1;
       callback._myws = this._myws;
       callback._historyforcall = this._historyforcall;
       callback.ReCall = function()
       {
        trace("ReCalling")
        callback.callcount++;
        var tempcallback = this._myws.stub.invokeOperation.apply(this._myws.stub, args);
        tempcallback.onResult = function()
        {
         callback.onResult.apply(callback,arguments)
        }
        tempcallback.onFault = function()
        {
         callback.onFault.apply(callback,arguments)
        }
       }
                return callback;
            }
        }
    }
    //=========================================================================================================================
    //覆写WebService 方法,使其指向WS,从而让WS能触法事件
    //=========================================================================================================================
    var o = WebService.prototype;
    o.onLoad = function(wsdl)
    {
     //当onLoad方法被触发时,尝试把该方法传给WS(parent)
        this.parent.onLoad(wsdl)
    }

    o.onFault = function(fault)
    {
     //同onLoad
        this.parent.onFault(fault)
    }
    //=========================================================================================================================
    //实现 WebService 所有的方法,并把方法指向 _myws
    //=========================================================================================================================
    var o = WS.prototype;
    //获取 WebService 提供的某个方法,但尝试过使用该方法,反回的是一个Object,因时间关系没有仔细研究该Object
    o.getCall = function(operationName)
    {
        return this._myws.getCall(operationName);
    }
    //获取 WebService 某个方法的参数列表数组(仅仅是传入参数类型),该列表数组中的元素是Object类型,里边包括参数名,参数类型等信息
    //WS 在对 WebService 进行扩展时,将使用到该方法
    o.getInputParameters = function(operationName)
    {
        return this._myws.getInputParameters(operationName);
    }
    //同getInputParameters,但该方法获取的是传出参数类型,关于传入传出的参数类型关系可以参考C#,java等高级语言关于这方面的知识
    o.getOutputParameters = function(operationName)
    {
        return this._myws.getOutputParameters(operationName);
    }

    o.onLoad = function(wsdl)
    {
        // this method will be called once the WSDL has been parsed and
        // the proxy created. It is meant to be overridden.
     // 该方法在WSDL被成功解析并且代理方法被成功创建时调用,这意味着你需要重写该方法
     // 该方法在WS扩展后,将被WebService调用,因而假如你重构了WebService的onLoad事件,WS的onLoad事件将不会被调用
    }

    o.onFault = function(fault)
    {
        // this method will be called if the WSDL cannot be parsed and
        // the proxy cannot be created. It is meant to be overridden.
     // 同onFault,不同在于WSDL分析出错时会调用
    }

    使用方法如下

    实例化:var myWebService = new WS (_weburl);

    调用时:

    var callback1=myWebService.ValidateMember(thismember);
     callback1.onResult=function(result){
      //成功处理
     }
     callback1.onFault= function()
     {
      if(this.callcount >= 2)
      {
       //如果重调用次数大于2 次  ,确实调用不了了.
    }else
      {
      //调用次数不足2 次,就重调用了ReCall
       this.ReCall();
      }
     }
     


    收藏到:Del.icio.us

发表评论

您将收到博主的回复邮件
记住我