2

The default maiximum input data size to an ASP.NET web service (NOT Wcf Service) apears to be 4 megabytes, but a process I am designing need to generate a maximum of 98, or 100 Megs to be on the safe side.

What factor in the Web.config do I need to increase to allow the larger size? Or is it somehwere else?

Web Services are not WCF Services, but both response to input being sent into them. Here is the method in the Web Service:

[WebMethod]
public string SubmitBatch(string batch)
{
    try
    {
        string filename = String.Format("BatchSubmission_{0}_{1}.xml", DateTime.Now.ToString("yyyy-MM-dd_HHmmss"), batch.Length.ToString());
        StreamWriter writer = new StreamWriter(@"C:\AFRSService\submissions\" + filename);
        writer.Write(batch);
        writer.Close();
        return String.Format("Your batch ({0}) was submitted!", filename);
    }
    catch (Exception ex)
    {
        return String.Format("Your batch failed submission due to: {0}", ex.ToString());
    }
}

The external method calling the web service and using the SubmitBatch() method looks like this:

AfrsServiceWS.AfrsService svc = new AfrsServiceWS.AfrsService();
string output = svc.SubmitBatch(input);

There is no problem for batches up to about 4 megabytes. After that I get a

System.Web.HttpException: Maximum request length exceeded.

The proposed closure is fine, I guess, but the supposed question with the five answers does not work in this case. I've set the maximum length as described and I still can't get the service to accept anything larger than 4 megabytes. This is frustrating.

Cyberherbalist
  • 12,061
  • 17
  • 83
  • 121
  • Your question is not clear. Are you importing data? Are you uploading files? Are you loading a large gridview? Please elaborate. – Techie Joe Oct 11 '13 at 22:04
  • 2
    Take a look at [this SO question and accepted answer](http://stackoverflow.com/questions/3853767/maximum-request-length-exceeded) – Icemanind Oct 11 '13 at 22:06
  • @TechieJoe: I thought that being an ASP.NET web service was clear enough, but if not... oh well. See the edit with some code added. – Cyberherbalist Oct 11 '13 at 22:16
  • icemanid beat me to the answer. This works like a charm for 'Maximum request length exceeded' errors. The reason I asked for clarification is that there are other similar scenarios that require other tweaks. – Techie Joe Oct 11 '13 at 22:19
  • There are two approaches. Either increase the max file size for IIS (as stated above) or use some kind of batch uploader (or write one) like [jquery file upload](http://blueimp.github.io/jQuery-File-Upload/). – Dustin Kingen Oct 11 '13 at 22:19
  • I did have a go with the answer @icemanind provided, and the first part of that one works, but for IIS7+ there is an additional tweak mentioned -- which when I try it causes a failure to update the web service. I have IIS 7.5 so don't know why it is a problem. – Cyberherbalist Oct 11 '13 at 22:31
  • ASMX is a legacy technology, and should not be used for new development. WCF should be used for all new development of web service clients and servers. One hint: Microsoft has retired the [ASMX Forum](http://social.msdn.microsoft.com/Forums/en-US/asmxandxml/threads) on MSDN. – John Saunders Oct 12 '13 at 05:48
  • @JohnSaunders, I know this, but have you tried to get a WCF service working to accept a 100 megabyte chunk of data??? I have, and it's not pretty! And if you check up on it, MS itself doesn't recommend a WCF service for this kind of huge file. I have a mainframe process that can accept up to 10,000 lines of 950-byte records. I have a very legacy FTP process that I am trying to get rid of, and my first choice is WCF, but I am having problems getting it done. – Cyberherbalist Oct 12 '13 at 06:46
  • Web services are not a file transfer mechanism. It's not likely to be trivial. But you _definitely_ don't want to do this with ASMX, which keeps at least _three_ copies of the message before processing it. WCF can do streaming. – John Saunders Oct 12 '13 at 08:02

0 Answers0