views:

1090

answers:

3

I am trying to save some bandwidth and include wsdl file in my flex/air application. Which url format should I use in order to load that file instead of the remote one.

I am using loadWSDL() method.

EDIT: wsdl file needs to be part of the application. I know I can use file://some/path for local files, but don't know how to load file which is inside application itself.

+1  A: 

If the file is local, just use the file URI scheme:

file://host/path/file.wsdl

If this doesn't work, check if the security sandbox features are blocking it.

In AIR apps, in order to access files in the application's temporary storage directory or the application's own directory, you need to use special app: or app-storage: URL schemes, though.

Like dirkgently said, you can always embed the file into the application, but as far as I know, you then won't be able to modify it afterwards in a persistent manner since it's not just a file in the filesystem. Probably the best option for you is to embed this file and if you later need to update it, have the app save an updated version into the File.applicationStorageDirectory (which you would then always check first before using the default embedded version.) Although I have no idea if using embedded XML files with the WebService classes is even possible.

See this article for info on how to embed external XML files into your app. This is how I've done it:

// 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());
hasseg
See question edit comment.
Dev er dev
Ok, now I (think to) understand embedding, but I still don't know how to create webservice using this.loadWSDL method accepts only string urls.
Dev er dev
@hasseg: thanks for such a wonderful explanation! You just beat me to it ;)
dirkgently
+1  A: 

wsdl file needs to be part of the application.

Have you tried embedding it inside the Flex/AIR project as a resource? Read this. For example, you can load static images shipped with your app by specifying the source as:

source="@Embed(source='relativeOrAbsolutePath')"
dirkgently
I couldn't find out how to use @Embed from code.
Dev er dev
You use the [Embed] metadata tag: http://livedocs.adobe.com/flex/3/html/help.html?content=embed_3.html
hasseg
A: 

Uf, this was ugly, so I'm answering for the reference. Thanks for insights to hasseg and dirkgently

Here is the code.

First, declare the variables:

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

Then, loading 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);

If someone have an idea to make this less ugly, please let me know.

EDIT: I just noticed edited answer, so instead of this code it was enough to use just:

loadWSDL('app:///path/to/my/file.wsdl');
Dev er dev