Error sending large (8 MB) excel file using HttpWebRequest for service-to-service

I am trying to send a large excel file to a holiday service (using a utility program).

Servicestack client and server services are deployed on different servers.

I use the following client-side code to download an excel file (size 8 mb)

taken from

http://www.codeproject.com/Articles/501608/Sending-Stream-to-ServiceStack

HttpWebRequest client = (HttpWebRequest)WebRequest .Create(ConfigurationManager .AppSettings["applicationUrl"] + @"/servicename/" + fileUpload.FileName + @"/" + FileType + @"/" + Utility.UserName + @"/" + Utility.EmployerID + @"/" + UploadedFrom); client.Method = WebRequestMethods.Http.Post; ////the following 4 rows enable streaming client.AllowWriteStreamBuffering = false; client.SendChunked = true; client.ContentType = "multipart/form-data;"; client.Timeout = int.MaxValue; // client.KeepAlive = false; //client.ProtocolVersion = HttpVersion.Version10; //client.ContentLength = 0; //client.Timeout = Timeout.Infinite; //client.AllowWriteStreamBuffering = true; Stream stream = fileUpload.InputStream; if (stream.CanRead) { stream.Copy(client.GetRequestStream()); } var response = new StreamReader(client.GetResponse().GetResponseStream()).ReadToEnd(); 

The above code works fine when the download file is 2-3 MB. it throws an error when the file size is about 8 MB.
when debugging it gives me the following error

 System.Net.WebException was caught HResult=-2146233079 Message=The remote server returned an error: (500) Internal Server Error. Source=System StackTrace: at System.Net.HttpWebRequest.GetResponse() at Myproject.Web.Controllers .Employer.FileUploadController .Upload(FileUploadViewModel fileUploadViewModel ,HttpPostedFileBase fileUpload ,String DataFileType ,String UploadedFrom) in d:\MyProject\projNewArch\Controllers\Employer\FileUploadController.cs:line 262 InnerException: 

I tried to change the settings that can be seen connected.

What could be the problem? Please, help

Update 1: I have IIS 8.5 on the server, so I think file size (8 MB) may not be a problem. I still need to add some settings to web.config to allow sending a large file via POST

UPDATE 2: solution found. Adding maxAllowedContentLength and maxRequestLength does the trick. Please check the link provided by Smartdev in the comments section.

+6
source share
1 answer

You still need to edit the web.config file. It should look like this:

 <system.webServer> <security> <requestFiltering> <requestLimits maxAllowedContentLength="10485760" /> </requestFiltering> </security> 

This will allow you to upload up to 10 MB

+1
source

All Articles