Large file upload does not work, ends up with 0 byte length file, why? RRS feed

  • Question

  • Hi all,

    I'm having trouble making large file uploads work. I'm trying to upload a file of almost 10MB (not at least large, but it already doesn't work). Hereunder my service interface and implementation.

    public interface IDataCollection
        [OperationContract(IsOneWay = true)]
        void UploadFile(UploadFileInfo info);
    public class UploadFileInfo
        public long Length { get; set; }
        public Stream Data { get; set; }
    class DataCollectionService : IDataCollection
        public void UploadFile(UploadFileInfo info)
            using (FileStream fs = new FileStream(@"c:\temp\test.xml", FileMode.Create, FileAccess.Write))
                int bufferSize = 1024;
                byte[] buffer = new byte[bufferSize]
                for (int length = info.Data.Read(buffer, 0, bufferSize); length > 0; length = info.Data.Read(buffer, 0, bufferSize))
                    fs.Write(buffer, 0, length);

    My client sends two files. One of which is about 10MB while the second is about 6KB in size. One the server side, I end up with two file, one of which is 0 bytes and the other 6KB. So, it seems that for the larger file, the Stream.Read() method immediately returns 0, leaving me with no data to write.

    Below is my configuration for the service.

          <service name="DataCollectionService" behaviorConfiguration="ServiceBehavior">
                <add baseAddress="http://localhost:1721/DataCollection/"   />
            <endpoint address="" binding="basicHttpBinding" bindingConfiguration="HttpBinding"
                <dns value="localhost"/>
            <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
            <behavior name="ServiceBehavior">
              <serviceMetadata httpGetEnabled="True"/>
              <serviceDebug includeExceptionDetailInFaults="True" />
          <binding name="HttpBinding" maxReceivedMessageSize="2147483647" transferMode="Streamed" sendTimeout="00:10:00" receiveTimeout="00:10:00" messageEncoding="Mtom">
            <readerQuotas maxArrayLength="2147483647" maxStringContentLength="2147483647" maxBytesPerRead="2147483647"/>
            <security mode="None"/>

    Can anyone help me out here? Thanks in advance.


    Wednesday, August 28, 2013 9:59 AM

All replies

  • Hi,

    Please try to add the following to your configure file:

    <bindings> <basicHttpBinding> <binding name="HttpBinding" transferMode="Streamed" closeTimeout="00:10:00" maxBufferPoolSize="250000000" maxReceivedMessageSize="250000000" openTimeout="00:10:00" receiveTimeout="00:10:00" sendTimeout="00:10:00" messageEncoding="Mtom"> <readerQuotas maxDepth="4500000" maxStringContentLength="4500000" maxBytesPerRead="40960000" maxNameTableCharCount="250000000" maxArrayLength="4500000"/> </basicHttpBinding> </bindings> ......

    <system.web> <httpRuntime executionTimeout="4800" maxRequestLength="500000000"/> </system.web> <system.webServer> <security> <requestFiltering> <requestLimits maxAllowedContentLength="500000000"></requestLimits> </requestFiltering> </security> </system.webServer>

    Here is a articles about how to upload large file in wcf: .

    Best Regards,
    Amy Peng

    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Thursday, August 29, 2013 8:47 AM
  • Hi,

    I changed the app.config on the server side, regenerated the client proxies and ran the application, but with no luck. Same result.

    I also read the article on CodeProject. I noticed that the writer uses a byte array to transfer the file data. I am using a Stream object. Should I switch to byte arrays? And, if yes, why?

    Another thought. I am testing the application from within Developer Studio 2012. Is it possible that the hosting environment that Developer Studio creates doesn't support this amount of data being transferred?

    Thanks again,


    Thursday, August 29, 2013 11:23 AM