title: Error receiving large report using Reporting Services Execution Web service
body: <p>I have an application which stores photo data in database. An SSRS report is used to generate reports of photos related to a specific entity. The information required to generate this report is stored in a separate database and very simply links a ReportId with a number of photos. The Reporting Services Execution Web service is used to render a report in Word format and output a byte array which is then used by the application.</p>
  
  <p>The issue is, there is a very clear and repeatable size limit beyond which the report is not received by the application. In each case the report is rendered successfully but the response is never sent as per the RS logs:</p>
  
  <pre><code>rshost!rshost!1bfc!03/14/2018-21:46:48:: e ERROR: HttpPipelineCallback::SendResponse(): failed writing response.
  rshost!rshost!1bfc!03/14/2018-21:46:48:: e ERROR: Failed with win32 error 0x0057, pipeline=0x0000027542592740.
  httpruntime!ReportServer_0-1!1bfc!03/14/2018-21:46:48:: e ERROR: Failed in 
  BaseWorkerRequest::SendHttpResponse(bool), exception=System.ArgumentException: Value does not fall within the expected range.
     at Microsoft.ReportingServices.HostingInterfaces.IRsHttpPipeline.SendResponse(Void* response, Boolean finalWrite, Boolean closeConn)
     at ReportingServicesHttpRuntime.BaseWorkerRequest.SendHttpResponse(Boolean finalFlush)
  library!ReportServer_0-1!1bfc!03/14/2018-21:46:48:: e ERROR: Throwing Microsoft.ReportingServices.Diagnostics.Utilities.ReportServerHttpRuntimeInternalException: RsWorkerRequest::FlushResponse., Microsoft.ReportingServices.Diagnostics.Utilities.ReportServerHttpRuntimeInternalException: An internal or system error occurred in the HTTP Runtime object for application domain ReportServer_SSRS_0-1-131655000672564770. ---&gt; System.ArgumentException: Value does not fall within the expected range.
     at ReportingServicesHttpRuntime.BaseWorkerRequest.SendHttpResponse(Boolean finalFlush)
     at ReportingServicesHttpRuntime.RsWorkerRequest.FlushResponse(Boolean finalFlush)
     --- End of inner exception stack trace ---;
  rshost!rshost!1bfc!03/14/2018-21:46:48:: e ERROR: HttpPipelineCallback::SendResponse(): failed writing response.
  rshost!rshost!1bfc!03/14/2018-21:46:48:: e ERROR: Failed with win32 error 0x10DD, pipeline=0x0000027542592740.
  </code></pre>
  
  <p>This appears to be directly related to some size limit of the service http response for the following reasons:</p>
  
  <ul>
  <li>The request itself is very small, just a Report Id i.e. httpRuntime maxRequestLength is not related, this has been tested.</li>
  <li>The error happens within a few minutes of the request i.e. httpRuntime executionTimeout is not related, this has been tested.</li>
  <li>I can reliably and repeatably add one photo too many to the report and it will fail, remove one photo and it renders and sends with no issues, add one photo and it will fail...</li>
  <li>The times to render vary so again it appears more related to size than some timeout.</li>
  <li>The report server execution logs show that the rendering is successful every time, regardless of whether the report is sent or not.</li>
  <li>I have reproduced the error using both the application which normally calls the report and a separate console app that simply generates a web service client and tries to render and receive the report as a byte array using the Render2 method.</li>
  <li>I have reproduced this error using SQL Server 2012 and SQL Server 2016, on several different report servers, including setting up a report server locally and running the server and request on the same machine. </li>
  <li>Regardless of the combination of photos, the report always renders successfully but fails to send around a bytecount of ~238,000,000 i.e. not related to some bad data.</li>
  <li>In all cases I am able to generate reports of the same size or greater through the Report Server portal with no issues.</li>
  </ul>
  
  <p>Has anyone experienced similar behaviour using the RS web service? I have searched online extensively without any luck. Any suggestions on how to address this issue would be greatly appreciated.</p>