Jump to content
Xtreme .Net Talk

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


Recommended Posts

Posted

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:

[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:

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:

<httpRuntime maxRequestLength="102400"/>

Is there something else I am missing?

What if the Hokey-Pokey IS what it's all about?
Posted

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:

 

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

 

Good luck :)

Never trouble another for what you can do for yourself.
Posted

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:

 

<!-- 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

What if the Hokey-Pokey IS what it's all about?
Posted

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?

What if the Hokey-Pokey IS what it's all about?

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...