3

I am writing a web application that generates a report from Bing Ads API, following the example seen here:

http://msdn.microsoft.com/en-us/library/bing-ads-reporting-request-and-download-a-keyword-performance-report-in-php.aspx

I have the code compiled, however when running, the server abruptly ends the request and returns ERR_INCOMPLETE_CHUNKED_ENCODING right at the beginning of this code block:

$waitTime = 30 * 1; 
$reportRequestStatus = null;

// This sample polls every 30 seconds up to 5 minutes.
// In production you may poll the status every 1 to 2 minutes for up to one hour.
// If the call succeeds, stop polling. If the call or 
// download fails, the call throws a fault.

for ($i = 0; $i < 10; $i++)
{
    sleep($waitTime);

    // PollGenerateReport helper method calls the corresponding Bing Ads service operation
    // to get the report request status.

    $reportRequestStatus = PollGenerateReport(
            $proxy, 
            $reportRequestId
            );

    if ($reportRequestStatus->Status == ReportRequestStatusType::Success ||
        $reportRequestStatus->Status == ReportRequestStatusType::Error)
    {
        break;
    }
}

I have tried to print out values and debug it line by line, but I cannot figure out what's causing this error. Googling the error doesn't bring up anything relevant either. I was wondering if anyone else has encountered this error before, and could tell me what is causing it?

Thanks!

eluong
  • 701
  • 1
  • 7
  • 17

1 Answers1

1

If im not mistaken - this is due to how you server is configured to handle various requests.

ASP.NET has some configuration settings but in a nutshell if you flush the buffer before the chunked request completes, you'll get this error. Here's a link I found some time ago when I ran into a similar problem. Good Luck!

Edit: Additionally here is an IIS page that describes how to enable the response handling that might be causing your issue: Enable or disable HTTP 1.1 chunked transfer encoding

To enable HTTP 1.1 chunked transfer encoding for the World Wide Web publishing service, use the following syntax: appcmd set config /section:asp /enableChunkedEncoding:True|False True enables HTTP 1.1 chunked transfer encoding whereas False disables HTTP 1.1 chunked transfer encoding. The default value is True.

..

and

To specify the default length of time that ASP pages let a script run before terminating the script and writing an event to the Windows Event Log, use the following syntax: appcmd set config /section:asp /scriptTimeout: timeSpan The variable timeSpan represents the maximum time (hh:mm:ss) that an ASP request can run before an event is written to the Windows Event Log. The default value is 00:01:30. http://technet.microsoft.com/en-us/library/cc730855(v=ws.10).aspx

also this guys explains it very well :

ASP.NET transfers the data to the client in chunked encoding (Transfer-Encoding: chunked), if you prematurely flush the Response stream for the Http request and the Content-Length header for the Response is not explicitly set by you.

Normally this should not be a problem because most modern HTTP clients are capable of handling both chunked as well as non-chunked server responses, de-chunking the chunked response automatically (Note that Chunked transfer encoding is defined only by HTTP 1.1 specification).

However, in my own case, I was making an asynchronous Ajax call to an ASP.NET web-service from javascript. And the web-method handling the request flushed the Response explicitly to the client, and then closed the Response (I needed to do so, because the request was issued from an auto-load call of an ExtJs store, and I needed to close the connection on the server for the client-side Store to accept and load the json serialized data).

http://www.rahulsingla.com/blog/2010/06/asp-net-sets-the-transfer-encoding-as-chunked-on-premature-flushing-the-response

Brandt Solovij
  • 2,124
  • 13
  • 24
  • Thanks! I will look into it. Is the solution quite trivial? – eluong May 18 '14 at 18:11
  • Some what - it just required some reading about more of the innerworkings of IIS that i wanted to know at the time but hey - it builds character right? – Brandt Solovij May 19 '14 at 17:09
  • I am not longer getting an `ERR_INCOMPLETE_CHUNKED_ENCODING` anymore, so modifying the `Content-Length` does 'solve' that particular error. However, now I am getting a `ERR_CONTENT_LENGTH_MISMATCH`, any suggestions? – eluong May 20 '14 at 13:45
  • just updated my answer with some more information. Essentially its a comingled result of settings that you will need to look at and evaluate on your end what works best for your environment and application(s). – Brandt Solovij May 20 '14 at 15:19
  • Thanks again, this definitely gives some material to work with for a solution. I'll see what I come up with and will let you know the result! – eluong May 20 '14 at 15:29
  • The issue was indeed a server configuration issue. Although I did not find what specifically caused the issue, moving to a new server resolved everything. Thank you for your help! – eluong Jun 24 '14 at 16:50