Writing an Array of Bytes from a .NET web service to a file

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • alkora
    New Member
    • Nov 2008
    • 1

    #1

    Writing an Array of Bytes from a .NET web service to a file

    Hi all-

    I have a .NET web service that returns a file in the form of an array of bytes. I'm wanting to write that into a file on the client's machine, but i've been unable to do so. I mean, I can print the array of bytes to a file, but its not converted back to the format it was originally in. The following is my service code:

    Code:
            [WebMethod]
            public byte[] DownloadFile(string FName)
            {
                System.IO.FileStream fs1 = null;
                fs1 = System.IO.File.Open(FName, FileMode.Open, FileAccess.Read);
                byte[] b1 = new byte[fs1.Length];
                fs1.Read(b1, 0, (int)fs1.Length);
                fs1.Close();
                return b1;
            }
    The following is what I have for my perl script so far:
    Code:
    use SOAP::Lite;
    
    open FILE, '>boot.ini' or die $!;
    
    #binmode FILE;
    
    my $soap = SOAP::Lite
        -> uri('http://tempuri.org')
        -> on_action( sub { join '/', 'http://tempuri.org', $_[1] } )
        -> proxy('http://localhost:1982/FileDownload.asmx');
    
    my $method = SOAP::Data->name('DownloadFile')
        ->attr({xmlns => 'http://tempuri.org/'});
    
    my @params = ( SOAP::Data->name(FName => 'c:\boot.ini') );
    
    $temp = $soap->call($method => @params)->result;
    
    #binmode $temp;
    
    print FILE $temp;
    close(FILE);
    Any suggestions for handling this array of bytes?

    Thank you.

    James Johnston
Working...