Setting up access to Flex Remote Objects without access to WEB-INF directory

When creating a project in Flex Builder if you select the application server type as J2EE you need to have access to the WEB-INF flex folder of the server and the services-config.xml configuration file of the remote server. So what do you do if you don't have access to the WEB-INF flex folder?

First create a normal Flex project (ie leave the application server type as 'none').

Next add these options to the addition compiler arguments in the flex compiler page of your project properties.

view plain print about
1-services /config/services-config.xml -context-root <your context root>

Where "" is your context root.

Next create a config directory and create this services-config.xml file:

view plain print about
1<?xml version="1.0" encoding="UTF-8"?>
2<services-config>
3    <services>
4        <service-include file-path="remoting-config.xml" />
5        <!-- may need a proxy config for deployment -->
6    </services>
7
8    <channels>
9        <channel-definition id="my-amf" class="mx.messaging.channels.AMFChannel">
10            <!-- server.name and server.port are replaced at runtime by server swf is loaded from -->
11            <!-- <endpoint url="http://{server.name}:{server.port}/{context.root}/messagebroker/amf" class="flex.messaging.endpoints.AMFEndpoint"/> -->
12            <endpoint url="http://<server name>:<server port>/{context.root}/messagebroker/amf" class="flex.messaging.endpoints.AMFEndpoint"/>
13
        </channel-definition>
14    </channels>
15
16</services-config>

Where is your server name and is your server port.

And lastly create a remoting-config.xml file:

view plain print about
1<?xml version="1.0" encoding="UTF-8"?>
2<service id="remoting-service" class="flex.messaging.services.RemotingService">
3
4    <adapters>
5        <adapter-definition id="java-object" class="flex.messaging.services.remoting.adapters.JavaAdapter" default="true" />
6    </adapters>
7
8    <default-channels>
9        <channel ref="my-amf" />
10    </default-channels>
11
12    <destination id="<my destination>">
13        <properties>
14            <source><path to remote object></source>
15        </properties>
16    </destination>
17</service>

Where is the name of your destination and is the dot path to the Java remote object.

There are a couple of issues with defining the server this way:

1. If you change the configuration file the Flex project will not compile automatically.

2. There is no way to set the server.name and server.port via compiler arguments so the server name and port need to be hard coded in the the configuration file. If you have testing and production servers you must remember to change these details in the configuration file and recompile (or have it changed automatically as part of your build process).

You apply this method to an existing an existing Flex project by changing the .flexProperties file to be like this

view plain print about
1<?xml version="1.0" encoding="UTF-8"?>
2<flexProperties flexServerType="0" toolCompile="true" useServerFlexSDK="false" version="1"/>

and following the steps above.

Related Blog Entries

TweetBacks
Comments (Comment Moderation is enabled. Your comment will not appear until approved.)
You could also define the channel set in your Flex project. See http://www.mischefamily.com/nathan/index.cfm/2009/... for an example of how to do this with MXML. (Note, the blog post focuses on Swiz, but the same technique can be used in any Flex project.)
# Posted By Nathan Mische | 2/8/10 12:01 AM
Nice solution Nathan. It does mean that you have to add the channelSet property to all of your remote objects but that's not a major issue.
# Posted By Justin Mclean | 2/8/10 12:20 AM