Is it possible to connect a flex application to two different BlazeDS servers?

浪尽此生 提交于 2019-12-13 04:28:36

问题


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.


回答1:


Is connecting one Flex application to two BlazeDS enabled servers completely impossible?

Yes! I see no reason why you wouldn't be able to do so, assuming the proper crossdomain.xml files are in place.

[Note, from here on out I assume you are using BlazeDS along with RemoteObjects/AMF]

To do this; you would most likely create different endpoints in your services-config file. The default endpoint [at least for the services-config included with ColdFusion] automatically points to the server that the SWF is served off of. There is no reason you can't create your own end points, even different endpoints in the same services-config file. You could also have the runpoints defind at runtime if you felt that was necessary.

I'm not sure why you'd be receiving session related errors; unless your server side code somehow requires sessions.




回答2:


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.



来源:https://stackoverflow.com/questions/9726410/is-it-possible-to-connect-a-flex-application-to-two-different-blazeds-servers

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!