加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

动态设置Flex与Java的通信通道

发布时间:2020-12-15 04:21:57 所属栏目:百科 来源:网络整理
导读:Flex 调用远程或所在web应用的 BlazeDS服务时,必须建立和远端的通道channel,才能正常通信。 例: fx:Declarations mx:RemoteObject id="remoteObject" destination="parkingIntroduce" / /fx:Declarations 在action代码中: /** ?* 得到服务器端根URL * sq

Flex 调用远程或所在web应用的 BlazeDS服务时,必须建立和远端的通道channel,才能正常通信。

例:

<fx:Declarations>
<mx:RemoteObject id="remoteObject" destination="parkingIntroduce" />
</fx:Declarations>

在action代码中:

/**
?* 得到服务器端根URL
* sq
?*/
public function queryServerRootURL():String{
var protocolPath:String = ExternalInterface.call("eval","window.location.protocol");//获取页面的protocol.得到 http:
var hostPath:String = ExternalInterface.call("eval","window.location.host"); //获取页面的host,得到 10.64.59.12:8080
var path:String = ExternalInterface.call("eval","window.location.pathname"); //获取页面的host,得到 /ivms8640v1.2/ParkingIntroduce-debug/ParkingIntroduce.html

var strs:Array = path.split("/"); ?//得到ivms8640v1.2
var projectName:String = strs[1];

var server_root_path:String = protocolPath + "//" + hostPath + "/" + ?projectName + "/";//http://10.64.59.12:8080/ivms8640v1.2/

server_root_path = protocolPath + "//" + hostPath + "/";//适用于1.2的url: ? ? http://10.64.62.180:8080
return server_root_path;
}

//初始化车位信息
public function initalParkingLot():void{
remoteObject.endpoint = queryServerRootURL() + "/messagebroker/amf";
}


转:

?Flex 调用远程或所在web应用的 BlazeDS服务时,必须建立和远端的通道channel,才能正常通信。 1. 通常的方式是 Flex 在编译时就指定远程的端点 Endpoint,service-config.xml 中的Endpoint 配置是 例如: Xml代码 复制代码 ? ?1. <endpoint url="http://{server.name}:{server.port}/{context.root}/messagebroker/amf" ?? <endpoint url="http://{server.name}:{server.port}/{context.root}/messagebroker/amf" ? ? 编译时指定的方式是在加编译参数,例如: 引用 -services "services-config.xml" -context-root "/HelloBlazeds" ? ?services-config.xml 需要放在当前目录下,或者指定BlazeDS所在的配置文件路径。 http://www.adobe.com/cfusion/communityengine/index.cfm?event=showdetails&productId=2&postId=12209 2. 在 <mx:RemoteObject/> 对象中指定Endpoint参数: ? ? ?例如: ? ? Xml代码 复制代码 ? ?1. <mx:RemoteObject id="roOrder" destination="Hello" showBusyCursor="true" endpoint="http://server:8080/HelloBlazeDS/messagebroker/amf" > ? <mx:RemoteObject id="roOrder" destination="Hello" showBusyCursor="true" endpoint="http://server:8080/HelloBlazeDS/messagebroker/amf" > ? ? ?1) 全路径: endpoint="http://server:8080/HelloBlazeDS/messagebroker/amf" > ? ? ?2) 基于contextRoot: endpoint="/HelloBlazeDS/messagebroker/amf" > ? ? ?3) 基于当前路径: ? endpoint="messagebroker/amf" > 总结: ? ? 对于Flex+BlazeDS集成开发,方式1,和2.1),2.2) 对于企业应用来说都不是最佳方案,因为他将 contextroot写死了,不便于移植,也就是说,编译后的 swf 放到其他应用下无法调用BlazeDS服务; ? ? 而对于互联网应用,如果假定 endpoint地址比较固定,编译时指定contextroot或endpoint全路径则是较好的选择,例如一个从google搜索信息Flex的小程序,放到桌面也能跑起来。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读