是否可以将Flex应用程序连接到两个不同的BlazeDS服务器? [英] Is it possible to connect a flex application to two different BlazeDS servers?

查看:261
本文介绍了是否可以将Flex应用程序连接到两个不同的BlazeDS服务器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题是可以从同一个Flex应用程序连接到两个不同的BlazeDS服务器吗?我已经读过这个问题:
一个Flex客户端应用程序可以连接到另一台服务器上运行的BlazeDS吗?
但是,它似乎在讨论将Flex客户端连接到不同服务器上的BlazeDS的可能性,必须在另一个服务器上另一个BlazeDS。

我也读过这个问题:
一个Flex客户端使用BlazeDS连接到两个webapps - 检测到重复的基于HTTP的FlexSession

在尝试过的尝试中,我得到了上面第二个问题中提到的错误:
检测到重复的基于HTTP的FlexSession,通常是由于远程主机禁用会话cookie。必须启用会话cookie才能正确管理客户端连接。

将一个Flex应用程序连接到两个BlazeDS服务器是完全不可能的吗?我们希望能够拥有一个通用功能的BlazeDS服务器,许多Flex应用程序都使用它们,每个Flex应用程序都有自己的本地BlazeDS服务器,以实现各自的功能。



//编辑
我现在正在这样做:



在我的mxml文件中,我定义了一个channset,像这样:

 < mx:ChannelSet id =dataService1Channel> 
< mx:频道>
< mx:AMFChannel id =dataService1AmfChannel
channelFault =dataService1Fault(event)
url =http:// localhost:7001 / dataservice1 / messagebroker / amf/>
< / mx:频道>
< / mx:ChannelSet>

然后我在下面配置的dataservice中使用这个channelset(当我使用FlashBuilder的时候自动配置

 < dataservice1:DataService1Service id =dataService1Service
fault =Alert。 show(event.fault.faultString +'\\\
'+ event.fault.faultDetail)
showBusyCursor =true
channelSet ={dataService1Channel}/>

另一个dataservice是这样定义的:

 < dataservice2:DataService2Service id =dataService2Service
fault =Alert.show(event.fault.faultString +'\ n'+ event.fault.faultDetail)
showBusyCursor =true/>

这些调用工作,我可以得到的数据,但我得到了我在表格中提到的警告Flex应用程序中的警报。如果我能够抑制这个警告,我会很高兴。

解决方案

那么我连接两个BlazeDS服务器时遇到同样的问题SINGLE Flex客户端(SWF)。实际上,flex文档中提到:每个用MXML或ActionScript编写的Flex应用程序最终都会编译成一个SWF文件,当SWF文件连接到BlazeDS服务器上创建一个flex.messaging.client.FlexClient对象来表示服务器上的SWF文件,SWF文件和FlexClient实例之间有一一对应的关系,在这个映射中,每个FlexClient实例都有一个名为id的唯一标识符, BlazeDS服务器生成的一个ActionScript单例类,mx.messaging.FlexClient,也被创建用于Flex应用程序访问其独特的FlexClient ID。



例如,有两个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.

//Edit The 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服务器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆