How to configure Web Service and consuming Web Site for uploading of large files?

joker77

Freshman
Joined
Sep 16, 2005
Messages
38
Location
Dublin
Hi,

I have a Web Service that contains a WebMethod to upload a file. The method contains a byte array parameter which the file is passed in as, and the file name. It then uses a FileStream to write the file to disk:
Code:
[WebMethod]
public string UploadContent(byte[] objFile, string ContentName)
{
     // Open FileStream
     FileStream fsFile = new FileStream(FolderName + ContentFileName, FileMode.Create);
     long FileLength = objFile.Length;
     fsFile.Write(objFile, 0, (int)FileLength);
     fsFile.Flush();
     fsFile.Close();
}
The Web Service consumer of this is a Web Site. On the .aspx page there is a FileUpload control, called ItemUpload. The code to upload the file is:
Code:
byte[] FileInBytes = ItemUpload.FileBytes;
myWebService.myWebService oWS = new myWebService.myWebService();
string sReturn = oWS.UploadContent(FileInBytes, ContentName);
This is working fine for small files (<4Mb), but when I try to upload a larger file I'm getting this message:
"The request failed with HTTP status 404: Not Found."

I have modified the Web.Config of the Web Service and also the consuming web site to allow for files of up to 100Mb:
Code:
<httpRuntime maxRequestLength="102400"/>
Is there something else I am missing?
 
executionTimeout

Perhaps the request is timing out due to the time it takes to upload the file. Try modifying the executionTimeout attribute in the web.config:

Code:
<!-- 100Mb filesize and 1 hour timeout -->
<httpRuntime
    [b]executionTimeout="3600"[/b]
    maxRequestLength="102400"
/>

Good luck :)
 
Re: executionTimeout

Perhaps the request is timing out due to the time it takes to upload the file. Try modifying the executionTimeout attribute in the web.config:

Code:
<!-- 100Mb filesize and 1 hour timeout -->
<httpRuntime
    [b]executionTimeout="3600"[/b]
    maxRequestLength="102400"
/>

Good luck :)
Thanks for taking the time to response MrPaul - I've posted this message in a couple of forums but am not having much joy!
Do you mean add this to the Web Service or Web Site config, or both?
The thing is though - when I step through the code in debug, and it tries to run the line to upload the file to the web service:
string sReturn = oWS.UploadContent(FileInBytes, ContentName);
the 404 error comes back within a second when I try a large file (65Mb). A 2Mb file works ok.
If it comes back within a second with the 404 error, this would seem to say it's not a Timeout? I'll give it a try though, thanks again
 
I've taken the Web site out of the equation, and just have a Web Service sitting on my local machine, and a Windows Client that consumes it. It looks to be some kind of timeout problem.

My web.config for the web service has the following entry:
<httpRuntime executionTimeout="3600" maxRequestLength="2024000"/>

When I try to upload a 16Mb file, that is call the method on the web service from the windows client passing in the file as a byte array - it works fine. When I try the same call with a 26Mb file, it returns a 404 Error.
Any ideas on how to configure IIS to allow this?
 
Back
Top