title: Excessive timeout on simple byte array reply from SOAP / WSDL Web Service call ... as if it started replying but never finishes?
body: <p>My C# client (running on .NET Framework 4.5.1 or later) calls a WSDL-defined SOAP web service call that returns a byte[] (with length typically about 100000).  We make hundreds of calls to this web service just fine -- they normally take just a few seconds to return.  But very intermittently, the call sits there for exactly 5 minutes and then throws an InvalidOperationException indicating that &quot;There is an error in XML document (1, 678)&quot;, with an InnerException that is a WebException &quot;The operation has timed out.&quot;  We've wrapped a try-catch around this call, look for those particular Exceptions, and then ask the user if they'd like us to retry it, and usually it works just fine on the next try.</p>
  <p>Looking at the logging on the server, the logs for the good calls and the intermittent bad calls look exactly the same.  In particular, in both cases we get the log statement at the very end of the web service, right before the &quot;return byteArray;&quot;... and it is doing that in the typical 3-15 seconds from the start of the call.  So, it seems the web service returns the byte array successfully, but the client that called the web service just never receives it.</p>
  <p>However, the client does NOT get the typical SoapException or WebException... for example, if we pause the web service in the debugger right before that return, then after 60 seconds the client will get a WebException &quot;The operation has timed out.&quot;  But we don't get that in this case... instead we are stuck there for a full 5 minutes before we finally get the InvalidOperationException mentioned above.  So, it is as if it started receiving the reply, so it doesn't consider it timed out the normal way, but it never gets the rest of the reply, and the parsing/deserializing of the XML containing the reply eventually times out.</p>
  <p>Question #1:  Any suggestions on what's happening here?  Or what we might be doing wrong in our web service that would result in a byte[] reply getting stuck mid-return intermittently?  I'd obviously love to fix the root problem.</p>
  <p>Question #2:  What controls the length of that 5 minute timeout??  Our exception handling for this would be okay except for the ridiculous 5 minute timeout.  After about 10 seconds, the user knows it is stuck because it normally returns in 10 seconds or less.  But they have to sit there and wait for 5 minutes before they can do anything.  We have set every timeout setting we could find to just 60 seconds, but none seem to control this.  We have set:</p>
  <ul>
  <li>In the server Web.config:  <code>&lt;httpRuntime executionTimeout=&quot;60&quot;&gt;</code></li>
  <li>In the server Global.asax.cs: <code>HttpContext.Current.Server.ScriptTimeout = 60;</code></li>
  <li>In both server and client:  <code>ServicePointManager.MaxServicePointIdleTime = 60000;</code></li>
  <li>In the client, right after we new up the WSDL-defined class derived from SoapHttpClientProtocol with all the web service calls, we call: <code>service.Timeout = 60000;</code></li>
  </ul>
  <p>We previously had those at their defaults or set to 100 / 100000 ... we lowered them all to 60 / 60000 to see if the 5 minute wait would come down at all (just in case one or more of them were being added into that 5 minutes).  But no, no matter what we changed any of those timeouts to, the timeout in this case remains exactly 5 minutes, every time it gets stuck.</p>
  <p>Does anybody know where the length of the timeout is set for when it generates an InvalidOperationException on the XML document containing the returned byte array due to an InnerException WebException with the timeout??  (please!)</p>