2010-11-13 51 views
0

我正在使用部署在SAP Web應用程序服務器上的Web服務來創建一些圖表。在將我的FLEX應用程序從開發版遷移到QA時,我也希望在flex中更改目標web服務的地址,以便他們從QA訪問Web服務。我所做的是將目標服務器地址添加爲URL參數,並將這些URL參數添加爲Flex中的flashvars。如何通過flashvars更改webservice URL

var wsdlUrl = window.location.search.substring(1);
flashvars.serverUrl = wsdlUrl;

現在,我嘗試了Web服務

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

的申報期間訪問的flashvars但Flash變量在某種程度上不是在聲明的時間訪問。

有沒有什麼辦法可以在運行時傳遞服務器URL,以便URL不需要在Flex應用程序中進行硬編碼?

最好的問候, 納庫爾

+0

您是否立即進行設置?作爲你的應用程序設置的一部分?您可能會更好地等待applicationComplete觸發,然後直接設置url。 – 2010-11-15 15:05:15

回答

1

剛去<your application path>\src\services

裏面的服務文件夾,裏面將與服務名稱的文件夾。在這個文件夾裏面,會有2個文件,其中打開名字以'_'(下劃線)開頭的文件。

在這個文件中,你可以修改鏈接/ URL。

0

您可以通過使用src文件夾下的Custom Config.xml文件來實現此目的。 在你的應用程序的main.mxml中有一個可以在應用程序中訪問的靜態變量。

public static var endpointUrl:String; 

撥打HTTPService調用到config.xml

<mx:HTTPService id="configSrv" 
       url="config.xml" 
       resultFormat="e4x" 
       result="configResultHandler(event)"/> 

結果處理將在你的標籤,你可以從config.xml中的值設置爲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")[email protected]; 
      if (endPointURL == "") 
      { 
       Alert.show("End Point not configured", "Error"); 
       return null; 
      } 
      Security.allowDomain(endPointURL); 
      return endPointURL; 
     } 

調用這樣

<cscustomreportservice:CSCustomReportService id="cSCustomReportService" useProxy="false" wsdl="{Main.endPointURL}" fault="Alert.show(event.fault.faultString + '\n' + event.fault.faultDetail)" showBusyCursor="true"/> 
靜態變量

示例config.xml供您參考:

<channels> 
    <channel id="endpoint" 
      endpoint="http://localhost:8080/myApp/"/> 
</channels>