Initialize webservice WSDL at runtime using Flex and Mate framework

2.3k Views Asked by At

I am developing a Flex application on top of Mate framework. In this application, I am using a webservice to retrieve data.
As this webservice as not a fix location URL (depending on where customers installed it), I define this URL in a config file. When the Flex application starts, it first reads this config file, then I would like to use the value I found to initialize the webservice.
But currently, I have no idea how to this.

Here is my EventMap.mxml

<EventMap>
<services:Services id="services" />

<EventHandlers type="{FlexEvent.PREINITIALIZE}">        
    <HTTPServiceInvoker instance="{services.configService}">
        <resultHandlers>
            <MethodInvoker generator="{ConfigManager}" method="loadFromXml" arguments="{resultObject}" />
        </resultHandlers>
        <faultHandlers>
            <InlineInvoker method="Alert.show" arguments="ERROR: Unable to load config.xml !" />
        </faultHandlers>            
    </HTTPServiceInvoker>

In this part, the ConfigManager parse the config file and intitialize a bindable property called webServiceWsdl

Here is my Services.mxml

<mx:Object>
<mx:Script>
<![CDATA[
    [Bindable] public var webservice:String;
]]>
</mx:Script>

<mx:HTTPService id="configService" url="config.xml" useProxy="false" />
<mx:WebService id="dataService" wsdl="{webservice}" useProxy="false"/>
</mx:Object>

How can I initialize this webservice property ?

3

There are 3 best solutions below

0
On

You can use this:

WebService.loadWSDL(runtimeWsdl) ;

Where runtimeWsdl is a String type variable containing the dynamic wsdl value.

2
On

Create a singleton class to encapsulate your configuration options and bind a property on the singleton instance into your service definition. We do this a fair bit.

[Bindable]
class Config
{
    private static var instance:Config;

    public static function getInstance ():Config {
        if (!instance)
            instance = new Config();
        return instance;
    }

    public var WEBSERVICE:String = "default value";
}

In Services.mxml:

<mx:WebService id="dataService" wsdl="{Config.getInstance().WEBSERVICE}" useProxy="false"/>

Obviously, you need to update your config instance when you load the config from the file.

0
On

I fail to see how this is different from the one in question. One is a bindable String, the other is a Bindable object.

I have found that when (in the above example) the bindable string associated with the wsdl parameter of the web service changes, the web service never updates.

As such, if the value of the string is not correct out of the gate, the web service will blow an error failing to find the wsdl, and will never try again...even when the string changes value.

Preston