问题描述
我的问题是是否可以从同一个 Flex 应用程序连接到两个不同的 BlazeDS 服务器?我已经读过这个问题:Flex 客户端应用程序是否可以连接到在不同服务器上运行的 BlazeDS?但是,它似乎在讨论将 Flex 客户端连接到不同服务器上的 BlazeDS 但不一定连接到不同服务器上的另一个 BlazeDS 的可能性.
My question is is it possible to connect to two different BlazeDS servers from the same Flex app? I have already read this question:Can a Flex client app connect to BlazeDS running on a different server?However, it appears to be discussing the possibility of connecting a Flex client to a BlazeDS on a different server but not necessarily to another BlazeDS on a different server.
我也看过这个问题:一个Flex客户端使用BlazeDS - 检测到重复的基于 HTTP 的 FlexSession
在我尝试过的尝试中,我收到了上面第二个问题中提到的错误:检测到重复的基于 HTTP 的 FlexSession,通常是由于远程主机禁用了会话 cookie.必须启用会话 cookie 才能正确管理客户端连接.
In attempts I have tried, I get the error mentioned in the second question above:Detected duplicate HTTP-based FlexSessions, generally due to the remote host disabling session cookies. Session cookies must be enabled to manage the client connection correctly.
将一个 Flex 应用程序连接到两个支持 BlazeDS 的服务器是完全不可能的吗?我们希望能够拥有一个通用功能"BlazeDS 服务器,供许多 Flex 应用程序使用,每个应用程序都有自己的本地 BlazeDS 服务器来实现自己的功能.
Is connecting one Flex application to two BlazeDS enabled servers completely impossible? We want to be able to have a "common functionality" BlazeDS server that is used by a number of Flex apps that each have their own local BlazeDS server for their own functionality.
//编辑我目前的做法是:
//EditThe way I'm currently doing it:
在我的 mxml 文件中,我定义了一个像这样的频道集:
In my mxml file, I'm defining a a channset like so:
<mx:ChannelSet id="dataService1Channel">
<mx:channels>
<mx:AMFChannel id="dataService1AmfChannel"
channelFault="dataService1Fault(event)"
url="http://localhost:7001/dataservice1/messagebroker/amf"/>
</mx:channels>
</mx:ChannelSet>
然后我在以下配置的数据服务中使用这个通道集(当我使用 FlashBuilder 的连接到 BlazeDS"功能时自动配置)
And then I'm using this channelset in the following configured dataservice (which was autoconfigured when I used FlashBuilder's "Connect to BlazeDS" funcion)
<dataservice1:DataService1Service id="dataService1Service"
fault="Alert.show(event.fault.faultString + '\n' + event.fault.faultDetail)"
showBusyCursor="true"
channelSet="{dataService1Channel}"/>
其他数据服务的定义如下:
The other dataservice is defined like so:
<dataservice2:DataService2Service id="dataService2Service"
fault="Alert.show(event.fault.faultString + '\n' + event.fault.faultDetail)"
showBusyCursor="true"/>
调用有效,我可以获得数据,但我收到了我在 Flex 应用程序中以警报形式提到的警告.如果我能抑制那个警告,我会很高兴.
The calls work and I can get the data but I'm getting that warning I mentioned in the form of an alert in the Flex application. If I could suppress that warning, I'd be happy.
推荐答案
我在用 SINGLE flex 客户端 (swf) 连接两个 BlazeDS 服务器时遇到了同样的问题.事实上,正如 flex 文档所说:
Well I faced the same problem while connecting two BlazeDS server with SINGLE flex client(swf). In fact as the flex documentation says:
每个用 MXML 或 ActionScript 编写的 Flex 应用程序最终都会编译成一个 SWF 文件.当 SWF 文件连接到 BlazeDS 服务器时,会创建一个 flex.messaging.client.FlexClient 对象来表示该 SWF 文件在服务器.SWF 文件和 FlexClient 实例具有一对一的映射.在此映射中,每个 FlexClient 实例都有一个名为 id 的唯一标识符,该标识符由 BlazeDS 服务器生成.还创建了一个 ActionScript 单例类 mx.messaging.FlexClient用于 Flex 应用程序访问其唯一的 FlexClient id."
"Every Flex application, written in MXML or ActionScript, is eventually compiled into a SWF file. When the SWF file connects to the BlazeDS server, a flex.messaging.client.FlexClient object is created to represent that SWF file on the server. SWF files and FlexClient instances have a one-to-one mapping. In this mapping, every FlexClient instance has a unique identifier named id, which the BlazeDS server generates. An ActionScript singleton class, mx.messaging.FlexClient, is also created for the Flex application to access its unique FlexClient id."
例如,您有两个 blazeDS 服务器.1) 远程 2) 本地和单个 FlexApp(swf)MyClient".
For example you have two blazeDS servers. 1) REMOTE 2)LOCAL and single FlexApp(swf) "MyClient".
步骤 1. MyClient 连接到 REMOTE blazeDS 服务器.这样就生成了一个唯一的 id.
Step 1. MyClient connects to REMOTE blazeDS server. So one unique id is generated .
第 2 步.现在 MyClient 连接到 LOCAL blazeDS 服务器.将使用在步骤 1 中生成的相同 id,因为只能为单个 FlexApp(swf) 生成单个 uniqe Id.
Step 2. Now MyClient connects to LOCAL blazeDS server. The same id generated in Step 1 will be used as only single uniqe Id can be generated for a single FlexApp(swf).
第 3 步.现在再次 MyClient 将重新连接到 REMOTE blazeDS 服务器.请记住,每次 FlexApp(swf) 连接到 blazeDS 服务器时,都会生成一个唯一的 FlexClient 以及唯一的 id.所以,现在在这第 3 步,我们已经有了第 1 步中生成的 id.所以,它肯定会抛出 Duplicate Session 异常.
Step 3. Now again MyClient will reconnect to REMOTE blazeDS server. Remeber that each time a FlexApp(swf) connects to blazeDS server a unique FlexClient is generated as well as the unique id. So, now at this Step 3, we already have the id generated in Step 1. So, definitely it will throw Duplicate Session exception.
解决办法:我在我的应用程序中找到并应用了一种解决方法.有用.每次 FlexApp(swf) 切换 blazeDS 服务器时,都会使生成的 id=null.
Solution:There is a workaround I found and applied in my application. It works.Every time the FlexApp(swf) switches the blazeDS server make the generated id=null.
FlexClient.getInstance().id=null;
在上面引用的例子中,在第 1 步之后使 id=null.现在当它连接到 LOCAL blazeDS 时,它不会使用第 1 步生成的 id.相反,它会在 LOCAL 工作时创建一个新的唯一 idblazeDS 模式.
In the above quoted example make the id=null after Step 1. Now when it will connect to the LOCAL blazeDS it will not use the id generated by Step 1. Instead , it will create one new unique id while working in LOCAL blazeDS mode.
同样,当您从 LOCAL 切换到 REMOTE 模式时(第 3 步),通过这段代码使 id=null.因此,现在当 FlexApp(swf) 连接到 REMOTE blazeDS 时,将生成一个新的唯一 Id,并且不会出现 Duplicate Session 异常.
Again when you switch from LOCAL to REMOTE mode (Step 3), make the id=null by this code piece. So , now when the FlexApp(swf) connects to the REMOTE blazeDS, a new unique Id will be generated and there will not be a Duplicate Session exception.
谢谢和问候,Anupam G.
Thanks and regards,Anupam G.
这篇关于是否可以将 flex 应用程序连接到两个不同的 BlazeDS 服务器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!