当前位置:主页>FLASH AS 编程>FMS>文章内容
  • FMS2 WebService 功能扩展
  • 来源:大猴子的花果山 作者:tinsgao 2007-10-22 【
FlashAs作品发表>>我要投稿 | FlashAs讨论区>>AS论坛
Flash Media Server学习站>>www.FMScn.com


代码文件如下

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





上一篇:FMS客户端 ActionScript 语言参考(1)   下一篇:关于FMS服务端数据流发布
  • 用户名:新注册) 密码: 匿名评论
  • 评论内容:(不能超过250字,需审核后才会公布,请自觉遵守互联网相关政策法规)

Copyright © 2006-2008 flashas.net All Rights Reserved.
网站内容咨询: admin#flashas.net (#为@) 联系QQ:40777822 浙ICP备06033001号
(本网站最佳浏览解析度为1024*768, 建议使用IE 6.0或以上版本浏览器。)