【问题标题】:How to change the webservice URL through flashvars如何通过 flashvars 更改 Web 服务 URL
【发布时间】:2010-11-13 02:49:31
【问题描述】:

我正在使用部署在 SAP Web 应用程序服务器上的 Web 服务来创建一些图表。在将我的 FLEX 应用程序从 dev 迁移到 QA 时,我还希望在 flex 中更改目标 Web 服务的地址,以便它们从 QA 访问 Web 服务。我所做的是将目标服务器地址添加为 URL 参数,并将这些 URL 参数添加为 Flex 中的 flashvars。

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

现在我尝试在 web 服务声明期间访问 flashvars

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

但是在声明期间无法访问 flashvar。

有什么方法可以在运行时传递服务器 URL,这样就不需要在 Flex 应用程序中硬编码该 URL?

最好的问候, 纳库尔

【问题讨论】:

  • 你是直接做这组的吗?作为应用程序设置的一部分?您可能最好等待 applicationComplete 触发,然后直接设置 url。

标签: apache-flex


【解决方案1】:

只要去&lt;your application path&gt;\src\services

在服务文件夹中,会有一个带有服务名称的文件夹。在这个文件夹中,会有2个文件,其中打开名称以'_'(下划线)开头的文件。

在此文件中,您可以修改链接/URL。

【讨论】:

    【解决方案2】:

    您可以通过使用 src 文件夹下的自定义 Config.xml 文件来实现此目的。 在您的应用程序的 main.mxml 中有一个静态变量,可在您的应用程序中访问。

    public static var endpointUrl:String;
    

    对 config.xml 进行 HTTPService 调用

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

    结果Handler会将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").@endpoint;
                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>
    

    【讨论】:

      猜你喜欢
      • 2019-08-07
      • 2015-07-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-03-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多