Flex remoteobject工作原理探讨
Flex访问远程服务都是通过AbstractService来实现的,其通常有3中具体的实现形式:HttpService、WebService和RemoteObject,应该来说RemoteObject是用起来最方便的一个,在项目实践中,我一般都用RemoteObject。Flex提供的数据管理功能就是包装RemoteObject与后台服务进行数据交互的。 假设后台是blazeds,在remoge-config配置了一个如下service <destination id="testService"?channels="my-amf"> <properties> <source>com.TestService </source> </properties> </destination> testService有个方法sayHello(String name){return “Hi,”+name;} 则可以在flex应用中定义一个RemoteObject对象,调用testService.sayHello方法轻松访问后台配置的服务。 <RemoteOject id =?"ro"?destination="testService"/> 在按钮或者其他事件中调用ro.sayHello("remoteObject")即可。 简单2句代码及可完成后台服务的调用,如完善的话再加上Result和Fault事件处理即可。那么remoteobject到底是如何工作的? var?con:NetConnection =?new?NetConnection(); var?url:String =?"http://localhost:8080/flex-test/messagebroker/amf"; try{ con.connect(url); }catch(error:Error){ Alert.show(error.message); } con.addEventListener(NetStatusEvent.NET_STATUS,netStatusHandler); con.addEventListener(SecurityErrorEvent.SECURITY_ERROR,securityErrorHandler); con.addEventListener(IOErrorEvent.IO_ERROR,ioErrorHandler); con.addEventListener(AsyncErrorEvent.ASYNC_ERROR,asyncErrorHandler); // var?message:RemotingMessage =?new?RemotingMessage(); message.destination =?"testService"; message.operation =?"sayHello"; message.messageId = UIDUtil.createUID(); message.body =?"remoteObject"; con.call(null,null,message); 通过上述代码,其实我们已经清晰的知晓,其先建立一个NetConnection,然后进行连接,然后包装RemotingMessage,然后发送message。 来源:http://blog.csdn.net/chuangxin/article/details/5692507 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |