Right now everything in my application looks like this:
service.url = FlexGlobals.topLevelApplication.serverURL + "/BusinessLayer/OurDataService.asmx/ThisIsMyWebservice";
instead of using FLEXGlobals to store a "global" variable of the URL, it would be nice if it could just read from an XML file. Or, just set the FLEXGlobals variable to read the XML file once, during Application initialization.
So it would be something like:
How can I do this? Any examples? I dont see much at all?
Or could it be standard FLEX practice to use hardcoded URLs instead? Lord I hope not...
1 person found this helpful
What do you actually need build script or to externalize you services?
What I need is a way to rebuild my application to point to a different server. Easily.
I have solutioned this using an XML file.
I ended up doing something similar to this guy:
I created a folder, outside of the "src" folder, called "settings". In it, there is an XML file, I named it "webserviceconfig.xml".
"webserviceconfig.xml" looks like this:
<?xml version="1.0" encoding="UTF-8"?>
When my application initializes, it sets a FLEXGlobal variable to store my server URL, like so:
//set the dynamic server URL address, read XML settings file for server URL
FlexGlobals.topLevelApplication.serverURL = webserviceconfig.url;
<fx:XML id="webserviceconfig" source="settings/webserviceconfig.xml" />
Now I am able to reference this all over my application:
myHTTPService.url = FlexGlobals.topLevelApplication.serverURL + "myWebServiceNameHere";
Now my application server URL is configurable and I no longer need to hardcode that anywhere in my application, except my XML configuration file.
I am glad to finally get this monkey off my back.
Thank you for your help and consideration, Caludiu Ursica.
I'd like to point out and mention that my "webservice" names are still hardcoded.
I could extend this to add configuration for those webservice names, but those are less important to me since they're re-used across all sub-domains and environments my code invokes. For me, those are static and never change, so they are okay to be hardcoded for now. Someone else using this example may find a need to configure the webservicenames explicitly themselves.
So, I would like to point out that this fix I implemented is only for server address/URL configuration, only.