Using Secure AMF Channels in Swiz

This question comes up quite a bit on the Swiz mailing list so I thought I'd write a blog post on how I handle this. For those new to Swiz, one very cool feature of the framework is the DynamicChannelSet wich allows you to remove the dependency on services-config.xml. Here is an example, from the Swiz docs, of how you would use DynamicChannelSet in your Bean Loader:

<BeanLoader xmlns="org.swizframework.util.*" xmlns:mx="http://www.adobe.com/2006/mxml">
<!-- custom channel set -->
<DynamicChannelSet id="myAmfChannel">
<serverPort>8080</serverPort>
<contextRoot>/demo-web</contextRoot>
</DynamicChannelSet>

<!-- user service -->
<mx:RemoteObject
id="userService"
source="userService"
destination="ColdFusion"
channelSet="{myAmfChannel}"/>

</BeanLoader>

The problem with DynamicChannelSet is that it only supports AMFChannels, not SecureAMFChannels. To get around this issue I just define my channel set in MXML like so:

<BeanLoader xmlns="org.swizframework.util.*" xmlns:mx="http://www.adobe.com/2006/mxml">
<!-- custom channel set -->
<mx:ChannelSet id="mySecureAmfChannelSet">
<mx:channels>
<mx:SecureAMFChannel
url="https://\{server.name\}:\{server.port\}/flex2gateway/cfamfsecure"
id="cfAMFSecure" />

</mx:channels>
</mx:ChannelSet>

<!-- user service -->
<mx:RemoteObject
id="userService"
source="userService"
destination="ColdFusionSecure"
channelSet="{mySecureAmfChannelSet}"/>

</BeanLoader>

It takes a few extra lines of code, but using this approach I can use secure channels and I have access to all AMFChannel properties, not just those exposed by DyanmicChannelSet. Also, you can use this approach to remove the dependency on services-config.xml for just about any Flex application, not just Swiz apps.

Comments
BlogCFC was created by Raymond Camden. This blog is running version 5.8.001.