Click here to Skip to main content
14,494,342 members

WCF Rest service - streaming download is VERY slow.

arielb asked:

Open original thread
Hello WCF Friends,i have a major problem.

i'm trying to download files using REST WCF, but it appears that, for example, 16MB file takes me 56 seconds, but in regular download (same source - from a website we have) - it takes 8 seconds.

In the client side, i'm reading the chunks like that:
// Initialize
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(test.FullURL);
request.Method = test.Method.ToString();
if (test.Method != TestMethod.GET)
            request.ContentType = "application/json";
            using (Stream requestStream = request.GetRequestStream())
               byte[] inputStringBytes = Encoding.UTF8.GetBytes(test.InputData);
               requestStream.Write(inputStringBytes, 0, inputStringBytes.Length);
using (var response = request.GetResponse())
               using (Stream responseStream = response.GetResponseStream())
                    System.Diagnostics.Stopwatch watch = new System.Diagnostics.Stopwatch();

                    char[] btArray = new char[5242880];
                     StreamReader rdr = new StreamReader(responseStream, Encoding.UTF8);
                     int idx = 0;
                     int length = 0;
                     while (!rdr.EndOfStream)
                        idx = rdr.ReadBlock(btArray, 0, 5242880);
                        //_result.actual += new string(btArray, 0, idx);

I'm using 5MB chunks, the file is 16MB as i said.

the configuration is basiclly:
<service behaviorConfiguration="httpBehavior" name="Name">
        <endpoint address="" binding="webHttpBinding" bindingConfiguration="webHttpBindingConfig"  behaviorConfiguration="web" contract="IService" />
        <binding name="webHttpBindingConfig" transferMode="Streamed" maxBufferSize="52428800" maxReceivedMessageSize="52428800">
          <readerQuotas maxDepth="32" maxStringContentLength="52428800" maxArrayLength="52428800" maxBytesPerRead="52428800" maxNameTableCharCount="52428800"/>
          <security mode="Transport">
            <transport clientCredentialType="None" proxyCredentialType="None" realm=""/>

(i even did large numbers in all configurations to see if that helps - nothing).

Am i missing something?

Tags: C#, WCF, REST


When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the The Code Project Open License (CPOL).

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100