问题描述
我的问题是可以从同一个Flex应用程序连接到两个不同的BlazeDS服务器吗?我已经读过这个问题:
但是,它似乎在讨论将Flex客户端连接到不同服务器上的BlazeDS的可能性,必须在另一个服务器上另一个BlazeDS。
我的问题是可以从同一个Flex应用程序连接到两个不同的BlazeDS服务器吗?我已经读过这个问题:
但是,它似乎在讨论将Flex客户端连接到不同服务器上的BlazeDS的可能性,必须在另一个服务器上另一个BlazeDS。
例如,有两个blazeDS服务器。 1)远程2)本地和单个FlexApp(swf)MyClient。
第1步。MyClient连接到REMOTE blazeDS服务器。所以生成一个唯一的ID。
第二步:现在MyClient连接到本地的blazeDS服务器。步骤1中生成的相同ID将被使用,因为只有一个单一的唯一标识符可以为单个FlexApp(swf)生成。
第3步。现在再次MyClient将重新连接REMOTE blazeDS服务器。请记住,每次FlexApp(swf)连接到blazeDS服务器时,都会生成唯一的FlexClient以及唯一的ID。所以,现在在这个步骤3,我们已经有了在步骤1中生成的id。所以,肯定会抛出Duplicate Session异常。
解决方案:
There是我找到并在我的应用程序中应用的解决方法。有用。
每次FlexApp(swf)切换blazeDS服务器时,都会生成id = null。
FlexClient.getInstance ).ID = NULL;
在上面引用的例子中,在步骤1之后使id = null。现在,当它连接到本地blazeDS它不会使用第1步生成的id。相反,它将在本地blazeDS模式下创建一个新的唯一的id。
再次从LOCAL切换到REMOTE模式时(步骤3),通过这段代码创建id = null。所以,现在当FlexApp(swf)连接到REMOTE blazeDS时,将会生成一个新的唯一ID,并且不会有重复会话异常。
感谢和问候,
Anupam G。
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.
I have also read this question:One Flex client connecting to two webapps using BlazeDS - Detected duplicate HTTP-based FlexSessions
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.
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:
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>
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"/>
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.
Well I faced the same problem while connecting two BlazeDS server with SINGLE flex client(swf). In fact as the flex documentation says:
"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."
For example you have two blazeDS servers. 1) REMOTE 2)LOCAL and single FlexApp(swf) "MyClient".
Step 1. MyClient connects to REMOTE blazeDS server. So one unique id is generated .
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).
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.
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;
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.
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.
Thanks and regards,Anupam G.
这篇关于是否可以将Flex应用程序连接到两个不同的BlazeDS服务器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!