Anyone familiar with Flex Data Services knows about services-config.xml.

This file usually contains security constraint definitions, channel definitions, and logging settings that each of the services can use. (more here)

It’s one of those config files that always feels more complicated than it needs to be, and to top it off, it’s a compile-time resource. This limits its flexibility, especially when it comes to channel definitions.

Why should you have to recompile your application whenever your channel definitions change? Let’s declare them in AS3 instead!

Here’s an example of two channel definitions from a services-config.xml file:

<channel-definition id="cf-polling-amf"

    <endpoint uri="http://{}:80/flex2gateway/cfamfpolling"



<channel-definition id="cf-rtmp"

    <endpoint uri="rtmp://{}:2048"


Now let’s look at the same two channel definitions in AS3:

var serverName : String = parameters.serverName;

var pollingChannel : AMFChannel = new AMFChannel ("cf-polling-amf",
    "http://&quot; + serverName + ":80/flex2gateway/cfamfpolling");
var rtmpChannel : RTMPChannel = new RTMPChannel ("cf-rtmp",
    "rtmp://" + serverName + ":2048");

pollingChannel.pollingEnabled = true;
pollingChannel.pollingInterval = 2000;

var channelSet : ChannelSet = new ChannelSet ();
channelSet.addChannel (pollingChannel);
channelSet.addChannel (rtmpChannel);

At first glance this code doesn’t appear to offer any advantage over the channels defined in services-config.xml. However in the AS3 code, the server name for the channels is passed in as a flashVar to the application.

This allows your application to determine at runtime which channels to use, and it also eliminates the need to compile the XML file into your application.

Two wins in my book.

Addendum: Adding Channel Definition Timeouts