4 Replies Latest reply on Dec 6, 2010 12:49 PM by Devtron

    HTTPService URL from configuration file?

    Devtron Level 3

      Hello,

       

      I have a need/requirement to use some type of configuration file for my FLEX builds. Right now I manually build my FLEX app.

       

      It would be nice to configure the URL for all HTTPService objects in an XML file, but I am unsure where that file would reside or what the XML structure should look like.

       

      I have looked at Flashbuilder4 Bible book but it doesnt cover much.

       

      Does anybody know of any good examples, tutorials, books, code links, demos, etc that show how to configure data access for a FLEX project?? Preferably in XML?

       

      I am a little lost in this area and any help or direction is appreciated.


      Thank you!

        • 1. Re: HTTPService URL from configuration file?
          Devtron Level 3

          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:

          FlexGlobals.topLevelApplication.serverURL= readMyXMLConfigurationFileHere();

           

          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...

          • 2. Re: HTTPService URL from configuration file?
            Claudiu Ursica Level 4

            What do you actually need build script or to externalize you services?

            C

            1 person found this helpful
            • 3. Re: HTTPService URL from configuration file?
              Devtron Level 3

              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:

              http://vatsalad.wordpress.com/2010/08/15/how-to-deploy-your-flex-app-to-different-servers- without-hardcoding-the-url/

               

              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"?>
              <webserviceconfig>
              <url>http://subdomain.domain.com:8080/BusinessLayer/MyDataServiceWSDL.asmx/</url>
              </webserviceconfig>

               

               

              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.

              • 4. Re: HTTPService URL from configuration file?
                Devtron Level 3

                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.