How to change the webservice URL through flashvars
I am using a webservice deployed on SAP Web Application Server to create some charts. While migrating my FLEX application from dev to QA, I also wish to change the address of my target webservices in flex, so that they access webservices from QA. What I did was add the target server address as a URL parameter and add these URL parameters as flashvars in Flex.
var wsdlUrl= window.location.search.substring(1);
flashvars.serverUrl = 开发者_如何学运维wsdlUrl;Now I try to access the flashvars during declaration of the webservice
<fx:Declarations>
<cscustomreportservice:CSCustomReportService
id="cSCustomReportService" useProxy="false" wsdl="{FlexGlobals.topLevelApplication.parameters.serverUrl}"
fault="Alert.show(event.fault.faultString + '\n' + event.fault.faultDetail)" showBusyCursor="true"/>
...
</fx:Declarations>
But the flashvars are somehow not accessible during the declaration time.
Is there any way I can pass the server URL during runtime so that the URL need not be hardcoded in the Flex application in anyway?
Best regards, Nakul
Just go to <your application path>\src\services
Inside the services folder, there would be a folder with the service name. Inside this folder, there would be 2 files, among them, open the the one whose name starts with '_' (underscore).
Inside this file, you can modify the link/URL.
You can achieve this by using a Custom Config.xml file under the src folder. In you application's main.mxml have a static var that is accessible across your application.
public static var endpointUrl:String;
Make a HTTPService call to the config.xml
<mx:HTTPService id="configSrv"
url="config.xml"
resultFormat="e4x"
result="configResultHandler(event)"/>
The result Handler will set the value from config.xml to the endPointUrl
//For calling the webservice uri end point
private function configResultHandler(event:ResultEvent):String
{
var xml:XML=event.result as XML;
var endPointURL:String="" + xml..channel.(@id == "endpoint").@endpoint;
if (endPointURL == "")
{
Alert.show("End Point not configured", "Error");
return null;
}
Security.allowDomain(endPointURL);
return endPointURL;
}
Now in your tag you can invoke the static variable like this
<cscustomreportservice:CSCustomReportService id="cSCustomReportService" useProxy="false" wsdl="{Main.endPointURL}" fault="Alert.show(event.fault.faultString + '\n' + event.fault.faultDetail)" showBusyCursor="true"/>
Sample config.xml for your reference:
<channels>
<channel id="endpoint"
endpoint="http://localhost:8080/myApp/"/>
</channels>
精彩评论