开发者

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

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.


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


I've faced the exact same problem. The out of memory is inevitable because you are using Byte arrays.

What we did is to flush the data on the hard drive, so in stead of being limited by your virtual memory your capacity for concurrent transactions is the HD space.

Then for transfer, we jut placed the file on the other computer. Of course in our case it was a server to server file transfer. If you want to de decoupled form the peer, you can use a file download in http.

So instead than responding with a file, your service could respond with a http url to the file location. Then when the client has successfully downloaded form the server with a standard HttpRequest or WebClient it calls a method to delete the file. In SOAP that could be Delete(string url), in REST that would be delete method on the resource.

I hope this makes sense to you. The most importnat part of this is to understand that in a scalable software especially if you are looking at 10000 clients (concurrent?) is that you may not use resources that are limited, like memory streams or byte arrays. But rather rely on large and easily expandable resources like a hard drive partition that coule eventually be on a SAN and IT could grow the partition as needed.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜