views:

41

answers:

1

I'm using a web service created in C#, its purpose is to get files from a server, and I'm trying to use it in AIR 2 (AS3).

Actually I can communicate with the web service with this library: http://labs.alducente.com/gophr/

When I call the webservice function I get this XML:

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"&gt;
  <soap:Body>
    <GetFileResponse xmlns="http://tempuri.org/"&gt;
      <GetFileResult>ZXN0byBlcyB1bmEgcHJ1ZWJhDQoNCnZhbW9zIGEgdmVyIHNpIHRyYWJhamENCg0KbXVhamphamFq</GetFileResult>
    </GetFileResponse>
  </soap:Body>
</soap:Envelope>

The file is encoded inside this tag:

< GetFileResult > 
ZXN0byBlcyB1bmEgcHJ1ZWJhDQoNCnZhbW9zIGEgdmVyIHNpIHRyYWJhamENCg0KbXVhamphamFq
< /GetFileResult >

So how can I decode and write to hard drive...

Web service code:

    [WebMethod]
    public byte[] GetFile(string path)
    {
       FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read);   
       // Create a byte array of file stream length
       byte[] ImageData = new byte[fs.Length];
       //Read block of bytes from stream into the byte array  
       fs.Read(ImageData,0,System.Convert.ToInt32(fs.Length));  
       //Close the File Stream   fs.Close();  
       return ImageData; 
       //return the byte data
    }
+1  A: 

Using static method decode from Base64 Class (http://www.foxarc.com/blog/article/60.htm) and using a simple as3 code I done this.

function done(serviceRespone:XML):void{
    var d = serviceRespone.children()[0].children()[0].children()[0];
    var bytes:ByteArray = Base64.decode(d);
    var newFile:File = File.desktopDirectory.resolvePath("MyNewFile.txt");
    var fileStream:FileStream = new FileStream();
    fileStream.open(newFile, FileMode.WRITE);
    fileStream.writeBytes(bytes);
    fileStream.close();
}
Delta
So, did it work?
bzlm
Yes it did work
Delta