How to transfer a large Zip file (50MB) using a WCF Service through SOAP to any client?

Defendore picture Defendore · Jul 21, 2010 · Viewed 9k times · Source

I have a WCF Service that returns a byte array with a Zip file (50MB) to any client that requests it. If the Zip is very small (say 1MB), the SOAP response is coming from WCF with the byte array embedded in it. But the response size is very huge even for a 1MB file. If I try to transfer the 50MB file the service hangs and throws an out of memory exception, because the SOAP response becomes huge in size.

  1. What is the best option available with WCF / web service to transfer large files (mainly ZIP format) as I am sending back a byte array. Is there any good approach instead of that for sending back the file?

  2. Whether WCF / web service is best way to transfer large files to any client or is there any other better option/technology available so that interoperability and scalability for 10,000 users can be achieved?

My Ccode is below:

        String pathfordownload = @"D:\New Folder.zip";
        FileStream F2D = new FileStream(pathfordownload, FileMode.Open,FileAccess.Read);
        BinaryReader binReader = new BinaryReader(F2D);
        binReader.BaseStream.Position = 0;
        byte[] binFile = binReader.ReadBytes(Convert.ToInt32 (binReader.BaseStream.Length));
        binReader.Close();
        return binFile;

A working piece/real piece of information will be really helpful as I am struggling with all the data available in Google and have had no good results for last week.

Answer

Henk Holterman picture Henk Holterman · Jul 21, 2010

You can transfer a Stream through WCF and then you can send (almost) limitless length files.