By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,372 Members | 1,906 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,372 IT Pros & Developers. It's quick & easy.

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

P: 1
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:

Expand|Select|Wrap|Line Numbers
  1.         [WebMethod]
  2.         public byte[] DownloadFile(string FName)
  3.         {
  4.             System.IO.FileStream fs1 = null;
  5.             fs1 = System.IO.File.Open(FName, FileMode.Open, FileAccess.Read);
  6.             byte[] b1 = new byte[fs1.Length];
  7.             fs1.Read(b1, 0, (int)fs1.Length);
  8.             fs1.Close();
  9.             return b1;
  10.         }
  11.  
The following is what I have for my perl script so far:
Expand|Select|Wrap|Line Numbers
  1. use SOAP::Lite;
  2.  
  3. open FILE, '>boot.ini' or die $!;
  4.  
  5. #binmode FILE;
  6.  
  7. my $soap = SOAP::Lite
  8.     -> uri('http://tempuri.org')
  9.     -> on_action( sub { join '/', 'http://tempuri.org', $_[1] } )
  10.     -> proxy('http://localhost:1982/FileDownload.asmx');
  11.  
  12. my $method = SOAP::Data->name('DownloadFile')
  13.     ->attr({xmlns => 'http://tempuri.org/'});
  14.  
  15. my @params = ( SOAP::Data->name(FName => 'c:\boot.ini') );
  16.  
  17. $temp = $soap->call($method => @params)->result;
  18.  
  19. #binmode $temp;
  20.  
  21. print FILE $temp;
  22. close(FILE);
  23.  
Any suggestions for handling this array of bytes?

Thank you.

James Johnston
Nov 18 '08 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.