My app appears to max out with the total size of all my files and not just the single file writes.
My app allows internal developers and admin to upload large files (<2MB each) up to a web app through a webservice, the webservice call File.WriteAllBytes(filename, bytes[] data) to write the files.
I have 6 files, 9.2MB in total. The increasing of the web.config maxRequestLength to a value above 9200 fixes this but I do thought this value would be for an individual file write and not the total file write, the maxRequestLength per instance of the webservice or something?
the maxRequestLength is like it's name indicate, the maximum size of the request from the web browser to the webserver. so this is why when you modified the maxRequestLength to 9200 KB, it allows you to upload the files.
for more information about maxRequestLength, visit the below link
maxRequestLength Web.Config
HttpRuntime
HC
Haissam,
The confusion for me was the Request vs the file upload/write to the web server, I wasn't sure if a request corresponded to a new instance of a webservice.
So the limit is on the request ok, a workaround would be to create a new request for each file instead of using the same request for all 6 files! Is this recommended? is there a downside? is it wiser to simply increase the maxRequestLength value (I do not know how big the maximum could be in the future, it all depends on the developers/admins file sizes which could be anything).
My present fix implements using which recreates a connection to the webservice for each file, is there another way to create a new request for each file to the same webservice?
string[] uris =new string[targets.Count];int count = 0;foreach (string fileNamein targets) {using (localhost.MyWeb myWebService =new localhost.MyWeb()) { myWebService.Url = myServer +"/myWeb.asmx"; entry.First = fileName; entry.Second = File.ReadAllBytes(fileName); packet.Add(entry);try { uris[count] = myWebService.Add(packet.ToArray())[0];//Here's where the files are passed to the webservice. I now add them one at a time for a new instance of the webservice each time. count++; }catch (Exception ex) { ...... } packet.Clear(); } }foreach (string uriin uris) LogToMessageWindow(uri);I dont think it's a good idea for each file you want to upload to create an instance of the webservice and open a connection. in this way, you are wasting resources in the server's memory. if i was in your case, i would simply modify the maxRequestLength to accomodate a maximum number of file size.
HC
Haissam,
What are the risks if any with increasing the max limit?
When you say, wasting resources you mean cpu time I suppose.
The individual instance of the webservice is disposed of each time after the file has been uploaded, it's really just an administration task, once every few weeks so I don't think the cpu usage is that much of a big deal, I'd imagine it would be slower that to upload within the same request.
Any alternatives please advise.
One negative point when increasing the value of the maxRequestLength is that you application can be attacked by sending large number of request. To avoid this, you should put limitation to file size being uploaded.
Even if you are disposing the object directly, this will may cause the server's cpu to be loaded with lots of processings. Imagine 10 users uploading files using your current way, the server's cpu will may be fully dedicated to them thus can't serve other requests.
HC
Actually only a single instance of the webservice is required, it's only when I invoke the actual webmethod that the request is started, therefore the potential fix is to call the webmethod for each file individually with a single instance of the webservice.
No comments:
Post a Comment