Encounter with services-config.xml in Adobe Flex
Posted by shardulbartwal on October 8, 2008
services-config file is used by us for connection to the server side code.One important thing which should be noticed here is that this file is used at compile time (as we also includes {-services “services-config.xml”} under compiler settings). If you are using this file then there will be a block like below.
<channels>
<channel-definition id=”my-amfphp” class=”mx.messaging.channels.AMFChannel”>
<endpoint uri=”http://IP of ur backend server/Project Name/amfphp/gateway.php”
class=”flex.messaging.endpoints.AMFEndpoint”/>
</channel-definition>
</channels>
The important thing here is ‘endpoint’ tag,Which have a uri field.This uri field is used to give
the path of backend server.But I will suggest not to put the this uri field here.As you know why?
Because if u will give this ip related information here then you can never change it because it will
be included in the build.So what we require to do when using this file,we should simply remove ‘uri’
from here and write it with your each and every remote object.And there you can get it from some
external xml,or by any other medium.
So the above block in services-config.xml should look like this only.
<channels>
<channel-definition id=”my-amfphp” class=”mx.messaging.channels.AMFChannel”>
<endpoint class=”flex.messaging.endpoints.AMFEndpoint”/>
</channel-definition>
</channels>
Hope you will enjoy it…………………..




Tom Chiverton said
“uri field is used to give the path of backend server.But I will suggest not to put the this uri field here”
No, you shouldn’t hardcode the name or IP of the server, instead you should use the {server.name} token – there are others given as examples in the default file.
That is, unless your application is talking to an end point that is on a different server to the deployed one, in which case it really should change so infrequently that sticking the host name in is fine.
Shardul singh Bartwal said
Hi Tom,
Thanks for commenting.
You are absolutely right.I m not saying to put uri hard code with Remote object.I have mantioned that we have to pick this from somewhere outside.That we can get from some other xml.
Like we can get that path from xml in to any class’s static variabe and then we can pass it in to uri.So latter on we can change the path in xml.Which will be reflected with our application.
Thnx…………..
Mick Powell said
Thanks Shardul,
Cool post which saved me a lot of time. One thing it might be worth mentioning is the endpoint property on the remoteobject where the uri value has to go, and maybe show that being set from a value in an xml configuration file as you suggest.
Many examples on the internet show the uri compiled into the services-config.xml file, and for code re-usability its an absolute must to get it out of there. Its a very important point to make and well done for doing so.
Classic said
can you plz put example to access uri with external file