代码之家  ›  专栏  ›  技术社区  ›  Marko

如何从文件中加载WSDL

  •  1
  • Marko  · 技术社区  · 16 年前

    我正在使用 loadWSDL

    编辑: wsdl文件需要是应用程序的一部分。我知道我可以用file://some/path 对于本地文件,但不知道如何加载应用程序本身内部的文件。

    4 回复  |  直到 16 年前
        1
  •  2
  •   hasseg    16 年前

    如果文件是本地的,只需使用 the file URI scheme :

    file://host/path/file.wsdl

    如果这不起作用,请检查 the security sandbox 功能正在阻止它。

    在空中应用程序中,以访问应用程序中的文件 temporary storage directory 或者 application's own directory ,您需要使用特殊的 app: app-storage: 不过,URL方案。

    正如Dirkgente所说,您可以始终将文件嵌入到应用程序中,但据我所知,之后您将无法以持久的方式对其进行修改,因为它不仅仅是文件系统中的一个文件。对于您来说,最好的选择可能是嵌入此文件,如果您以后需要更新它,请让应用程序将更新的版本保存到 File.applicationStorageDirectory (在使用默认的嵌入式版本之前,您总是先检查它。)尽管我不知道是否可以将嵌入式XML文件与WebService类一起使用。

    看见 this article 有关如何将外部XML文件嵌入应用程序的信息。我就是这样做的:

    // note: common sense says that the mimeType should be "text/xml" here but
    // it doesn't work -- this does, though. who knows why.
    [Embed(source="File.xml", mimeType="application/octet-stream")]
    private const _fileXMLClass:Class;
    private var _fileXML:XML = XML(new _fileXMLClass());
    
        2
  •  1
  •   dirkgently    16 年前

    您是否尝试将其作为资源嵌入到Flex/AIR项目中?阅读 this source 作为:

    source="@Embed(source='relativeOrAbsolutePath')"
    
        3
  •  0
  •   Marko    16 年前

    Uf,这太难看了,所以我要回答这个问题。感谢hasseg和Dirkgenly的见解

    这是代码。

    [Embed(source="/ws/wsdl/LoginService.wsdl", 
           mimeType="application/octet-stream")]
    private const _fileXMLClass:Class;
    private var _fileXML:XML = XML(new _fileXMLClass());
    

    然后,加载wsdl:

    var file : File = dir.resolvePath(name + ".xml");
    var stream : FileStream = new FileStream();
    stream.open(file, FileMode.WRITE);
    stream.writeUTFBytes(getWsdl().toXMLString());
    stream.close();
    loadWSDL(file.url);
    

    loadWSDL('app:///path/to/my/file.wsdl');
    
        4
  •  0
  •   johnny    11 年前

    我在flash builder air mobile应用程序中使用了下面的代码,它可以正常工作,可能对其他人有所帮助。我使用url加载器从web服务获取文件内容,并将其向下写入air应用程序文档目录中的xml文件。

    var url:URLRequest = new URLRequest(Globals.deviceSettings.endpoint);
                    loader.load(url);
                    loader.addEventListener(Event.COMPLETE, loaderComplete);
    

    获取web服务的状态,如果它是200,则可用并启动。 loader.addEventListener(HTTPStatusEvent.HTTP_STATUS, ldrStatus);

    function loaderComplete(e:Event):void
                {
    
                        var f:File= File.documentsDirectory.resolvePath("source/category.xml");
                        var _xml:XML = new XML(loader.data);
                        var fs:FileStream = new FileStream();
                        fs.open(f, FileMode.WRITE);
                        fs.writeUTFBytes(_xml.toXMLString());
                        fs.close();
                        popup.close(true);
                        var popup:MyPopupComponent = new MyPopupComponent();
                        popup.show("Successfully updated from the server",this);
                        popup.close();
                }
    

    您可以根据需要使用file.documentdirectory或application或您选择的目录。请记住,出于安全考虑,某些路径是只读的。如果你想写回那些文件,你将不能,但只是为了阅读的目的,这是一个好主意,把文件放在那里。