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"?>
3    <services>
4        <service-include file-path="remoting-config.xml" />
5        <!-- may need a proxy config for deployment -->
6    </services>
8    <channels>
9        <channel-definition id="my-amf" class="mx.messaging.channels.AMFChannel">
10            <!-- and server.port are replaced at runtime by server swf is loaded from -->
11            <!-- <endpoint url="http://{}:{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"/>
14    </channels>

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="">
4    <adapters>
5        <adapter-definition id="java-object" class="" default="true" />
6    </adapters>
8    <default-channels>
9        <channel ref="my-amf" />
10    </default-channels>
12    <destination id="<my destination>">
13        <properties>
14            <source><path to remote object></source>
15        </properties>
16    </destination>

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 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

Comments (Comment Moderation is enabled. Your comment will not appear until approved.)
You could also define the channel set in your Flex project. See 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