How to load WSDL from file - apache-flex

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.

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());

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')"

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');

I use below code in flash builder air mobile app and it works, may help some else. I get file contents from a web service using url loader and wirte it down to a xml file in document directory of my air app.
var url:URLRequest = new URLRequest(Globals.deviceSettings.endpoint);
loader.load(url);
loader.addEventListener(Event.COMPLETE, loaderComplete);
get the status of web service, if it is 200 then available and heads up.
loader.addEventListener(HTTPStatusEvent.HTTP_STATUS, ldrStatus);
and in the eventlistener
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();
}
you can use file.documentdirectory or applicaiton or your choice directory as per your need please keep in mind that some of the paths are read only for security. if you want to write back to those files you wont be able but just for reading purposes it is a good idea to place the files there.

Related

Access static files on server from RCL

I've read dozens of questions but none seem to work for me. I'm not using IIS. I'm using ASP.Net Core 3.1 with Kestrel.
I have a Razor Class Library with a resources folder, in that I have folders like css, js, content, etc. I use this library so all of my common Web Api projects can share common files instead of duplicating them everywhere. To do this, I followed the guide from here. Please see there for how Startup is configured.
That works great, I can access those files by going to e.g. localhost/css/site.css. In my cshtml files, I can include that file by doing <link rel="stylesheet" href="~/css/site.css"/>
The problem arises when I try to access those files from a controller. I have a sister folder to css called content which contains json files. I can view that file by going to localhost/content/test.json, but I can't figure out how to access it from a controller.
What I'd like to do is make an HTTP request to ~/content/test.json and download its contents, but the path is not found.
I've tried using Url.Content to map a relative path to the absolute path, but it doesn't work.
var url = Url.Content("~/content/test.json"); // spits out "/content/test.json"
I've DI'd IWebHostEnvironment into the controller and tried to access the ContentRootFileProvider and the ContentRootPath and WebRootPath, but those paths aren't right either. They are pointing to my currently running service's wwwroot's parent and wwwroot, respectively.
I've tried creating my own file provider:
var filesProvider = new ManifestEmbeddedFileProvider(GetType().Assembly, "resources");
var content = filesProvider.GetDirectoryContents("content");
var fileInfo = filesProvider.GetFileInfo(Path.Combine("content", "test.json"));
This successfully finds the file and claims it exists, but the fileInfo's PhysicalPath is always null.
I just want to do something like this:
string SomeMagicMapFunction(string s) => ????
var webClient = new WebClient();
var json = webClient.DownloadString(SomeMagicMapFunction("~/content/test.json"));
Where am I going wrong? Any pointers are appreciated.

loading css on runtime is half-failure/half-success

I have tried for my app to load fonts on request. I tried to read fonts from the a project directory which is created by my app, and it reads all the info it needs.
First of all, I want to ask if there is a way to know if there is an app-storage:// like in adobe air, because THAT IS KILLING ME! I cannot create temporary files to be read on runtime by the app and place, for example, a style sheet with the new loaded fonts on runtime via JS.!
If there is one, please let me know!!!
Now a very dirty solution. This is what I had done up to now:
Just to let know everybody, my solution relies on :
run the app as administrator (a must to have)
softlinking the user's project font folder.
now lets get the facts:
webkit cannot render fronts coming from a "file:///" url
I had tried using file:/// with no success, and neither converting the SVG fonts to base64 did the trick at all. Trying to do on runtime stylesheets was even worse, so looking for solutions I had to rely on command prompts. For now I'm running this on windows and works pearls:
var WinDoExec = function(cmdline){
var echoCmd = ["C:\\Windows\\System32\\cmd.exe","/C"];
echoCmd = $.merge(echoCmd,cmdline);
console.log(echoCmd);
var echo = Ti.Process.createProcess(echoCmd);
echo.setOnReadLine(function(data) {
console.log(data.toString());
});
echo.stdout.attach(echo.stdin);
echo.launch();
};
so from here, I had to create a mklink (soft link on ntfs) from the user's project font folder to the application font directory, so it could be accessible on runtime.
WinDoExec(["mklink","/D","C:\\Program Files(x86)\\myapp\\Resources\\assets\\fonts\\userfonts","C:\\Users\\windowsuser\\projectAppFolder\\ProjectName\\Fonts"]);
with this, creating a soft link into the application in runtime fixes the issue of loading the custom fonts for the user's project into the runtime app...
I know this is kinda "abusive" with the program environment, but I really wish there was a way for the app to have a url accessible path (such storage url path or temporary url path) in order to process things on runtime. I could copy the fonts into the temporary url container folder and do my stuff without affecting the app system folder at all.
So if you guys on tidekit read this, please allow developers to have accessible url paths for temporary objects (like user's svg/ttf files) that I can copy there and use on runtime.
Thanks.

What's the recommended way to load an internal file on the web site?

We've got a certain image in the \Images folder of our web site. We need to include that image in an OpenXml file we're generating internally, and for that we're using the following snippet:
var logo = Server.MapPath(#"~\Images\logo-new.png");
var imagePart = mainPart.AddImagePart(ImagePartType.Png); // mainPart is of type MainDocumentPart
using (var stream = new FileStream(logo, FileMode.Open))
{
imagePart.FeedData(stream);
}
Then later imagePart is used for embedding in the document.
This code works fine in development, but in deployment we're getting a System.UnauthorizedAccessException when we try to open the file for streaming.
Clearly there is an access permission problem, since Server.MapPath() is converting the web path to an absolute path on the server drive, and the IIS user doesn't have rights to that. We might be able to get around it by granting access to everyone, but something tells me that this is not the textbook way of doing it. Surely there must be a way of accessing this file that doesn't require us to start futzing with access permissions to the web deployment folder?
Solved, by including the file as a resource rather than by trying to access it through the file system:
var logo = Resources.logo_new;
var imagePart = mainPart.AddImagePart(ImagePartType.Png);
using (var stream = logo.ToStream(ImageFormat.Png))
{
imagePart.FeedData(stream);
}
Hat tip to this answer for the .ToStream() extension.

Download and run file in client machine using asp.net

I'm trying to download and run a file to the client machine. The client is aware of that.
It's a ttkgp file that's dynamicly generated.
I've tried using Processs.Start() that worked fine on my local machine (first saved the file to C:\ then lunched it), but it's not working from the server. It's not my server but a hosted one. They are trying to help but no luck so far.
I've seen this code:
public void ProcessRequest(HttpContext context)
{
string fileName = context.Request.QueryString["filename"];
FileInfo fi = new FileInfo(fileName);
context.Response.ContentType = "application/x-rar-compressed";
context.Response.AppendHeader("Content-Disposition",
string.Format("attachment; filename=download{0}", fi.Name));
context.Response.WriteFile(fileName);
context.Response.End();
}
But since I dont know what's "HttpContext context" is, I've no idea if it works.
Is it some server previlges need to be changed? or simply this code will do the trick?
Thank you
UPDATE (24.6.12): I'm nearly finished with the problem, all I need now is to know how to open an html page in a new tab / window and close it second later. Once I'm done, I'll post back here all the process, I'm sure it'll help other people.
UPDATE (26.6.12):
Here's what I've got:
The goal is to download an TTKGP file from asp.net webiste to local user machine and run it.
Step 1: generate the file with code behaind (c#) on the server (V)
Step 2: copy the file or it's content to user machine (X)
Step 3: run the file using JS (V)
Here's the thing: I CAN copy from a text file on the server to a text file on the user machine, but not from TTKGP files. It's strange because this are just text files just a different extantion.
The code for copying text files:
enter code here
function copyremotetxt() // works
{
// copy the txt file
var fso = new ActiveXObject("Scripting.FileSystemObject");
var newfile = fso.CopyFile("remote.txt", "C:\\Users\\***\\local.txt");
}
Perhaps I can change the file type on the user machine?
Notice 1: I know that's a security issue, the site is just for known user not the open public
Notice 2: I know there are better ways to get the task done, but there are strict limitaions on many things
Thanks for those how can help!!
This code will do the trick. It will prompt the client to download and save the file on his computer at the location he decides. What happens next with this file is the client's decision, not yours. He might simply close the Save As dialog, interrupt the download, delete the file, ... It's up to him.
Another remark: this code is extremely dangerous because it allows the client to pass any filename he wants as query string parameter and download it. So he could read absolutely all files on the server which is probably not something that you want to happen.
Ok, this need a different aproach.
I'll try using JavaScript do read the file on the server, rewrite it in the user machine and activate it. Any clues would be grate! For a start, how to I read file in JS? I'm new to it.

Flash XML config file problems with asp.net MVC

I'm creating an asp.net MVC app, first time I've done this. I have a flash component I need to use in a view. I have included the SWF files etc in the Contents folder and referenced it from my view, the flash file loads when you get to the view, great.
The problem occurs because the flash file references and XML file for its configuration data, and I'm getting an error accessing that XML file. I'm guessing this is because flash is looking for a relative path and is using the URL for the page, which is obviously an MVC url and so does not refer to an actual location on disk, so the XML file is not there.
I guess the obvious answer is the alter the flash file to look in the contents folder for the XML file, but that means re-compiling the flash, and I know very little about flash so I'd like to avoid doing that. So is there any way to get the XML file to show up in the same URL as the view, so at the moment, the page with the flash component on is located at htttp://localhost/upload/ so I guess the XML file needs to be accessible from http://localhost/upload/flash-settings.xml?
If there's any other better way to do this, without editing the flash file, im open to that too,
Add this Action to the FlashUpload Controller:
public class FlashUploadController : Controller
{
[AcceptVerbs(HttpVerbs.Get)]
public ActionResult FlashSettings()
{
var fileName = Server.MapPath("~/Contents/flash-settings.xml");
return new FilePathResult(fileName, "text/xml");
}
}
And this route to the RouteTable:
routes.MapRoute("FlashSettings", "upload/flash-settings.xml",
new { Controller = "FlashUpload", Action = "FlashSettings" });
You'll need to either set the routing mechanism to allow for direct files access to the /upload/ folder, or create a Controller Action which will return an XML stream (dynamic or the one read from the physical XML file), and point your SWF to that Route. I'd go with the second option, as it is much flexible.

Resources