Accessing services-config.xml values from Flex at runtime
Recently I found this magic class in the Flex 3 SDK called ServerConfig. This class is great… What it allows you to do is access values that you defined in your services-config.xml file used to define the communication channels between Flex and your server.
Take the following services-config.xml file for example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | <?xml version="1.0" encoding="UTF-8"?> <services-config> <services> <service id="amfphp-flashremoting-service" class="flex.messaging.services.RemotingService" messageTypes="flex.messaging.messages.RemotingMessage"> <destination id="amfphp"> <channels> <channel ref="my-amfphp"/> </channels> <properties> <source>*</source> </properties> </destination> </service> </services> <channels> <channel-definition id="my-amfphp" class="mx.messaging.channels.AMFChannel"> <endpoint uri="gateway.php" class="flex.messaging.endpoints.AMFEndpoint"/> </channel-definition> </channels> </services-config> |
As you can see, we’re setting the endpoint for our my-amfphp channel to gateway.php. What if you wanted to read that value into your Flex application? You could use the following code:
trace(ServerConfig.getChannel("my-amfphp").endpoint);
Check out the ServerConfig for more information!
| Print article | This entry was posted by Danny Kopping on February 11, 2010 at 9:24 pm, and is filed under ActionScript 3.0, Flex, Security. Follow any responses to this post through RSS 2.0. You can leave a response or trackback from your own site. |
about 1 year ago
Wow… thanks a lot man!!!!
about 1 year ago
My pleasure, Diego
about 1 year ago
good, but… can i do this on the contrary?? Sending some Url value to services-config?
about 1 year ago
Not sure… What do you mean exactly?
about 1 year ago
yeah.. if i put the endpoint, it would be static. But i want a dynamic one.. if some day i change my baseUrl i have to change my code too, and i don’t want that.
ok, so guess that i send the Url from php to Flex directly using flashVars, and i receive it in the MXML code.. how can i send it to the services-config??
Thanks for your answer
about 1 year ago
ok, if somebody see this, i’ve solved it.
I’ve created a AMFChannel directly in ActionScript, and i’ve taken the baseUrl from server using flashvars.
If Somebody is interested, write it here and i will try to help. See you
about 1 year ago
diEgo,
Please post!
about 1 year ago
look at this…. http://margopowell.wordpress.com/2009/05/18/reading-flashvars-in-flex/