Search code examples
c#xmlweb-servicestimeoutlarge-data

.asmx request timeout when returning a very large string


We have a couple of .asmx soap web services that handle communication between our web gui and our backend app server. Recently we went from running our Visual Studio 2010 solution in the built in web server to running it through IIS 7.5. Right away we started experiencing very slow response times and started getting various exception that we weren't seeing before, like timeouts & serialization errors in our xml's.

We've tried to narrow the problem down to a minimum, but are short a solution so now we're throwing it "out there" to see if anyone have experienced the same or maybe have a solution.

PS. We know that .asmx web services are outdated, but we can't convert the services to WCF at this time. DS.

This code will reproduce the error:

[WebMethod]
public string DebugGetAuditTrail()
{
   const string data = "Some random text that is not very interesting. ";
   StringBuilder lotsOfData = new StringBuilder();
   for(int counter=0; counter<100000; counter++)
   {
      lotsOfData.Append(data);
   }

   return lotsOfData.ToString();
}

Our web.config states:

<httpRuntime executionTimeout="600" requestValidationMode="2.0" maxRequestLength="1400000"/>

Thanks in advance!


Solution

  • Ideally it is not advisable to send huge amount of data using web-service. However, to deal with such situations, the best way is to break apart the data in small packets.

    What you can do is, create a header which indexes the data packets. Once the header is received, configure the server to send the remaining part of data.