views:

921

answers:

4

Hi,

I have a standard SOAP webservice with a WebMethod which accepts a byte array and then performs a

[WebMethod(true)]
WriteFile(byte[] Data, string FilePath)
{

    File.WriteAllBytes(FilePath, Data);
}

If this process is passed a large file, e.g. 2 meg it is bombing out with the following error message:

Insufficient system resources exist to complete the requested service

Looking at the stack trace i'm getting:

  • System.IO.File.WriteAllBytes
  • System.IO.FileStream.Write
  • System.IO.FileStream.WriteCore
  • System.IO.__Error.WinIOError
  • System.IO.IOException: Insufficient system resources exist to complete therequested service

I've tried all the obvious things such as setting the maxrequestlength and executing timeout to more realistic settings:

<httpRuntime maxRequestLength="409600" executionTimeout="900"/>

It still seems to fail over with the above. If you send a smaller file it saves to disk fine.. So it's either file size or time that's the issue.

Does anyone know of anything else i can do to sort this out?

Thanks

Dave

A: 
Jeremy McGee
Hi. Looking at MSDN it says that the default is 4096 (4MB)... It says it's in kilobytes.. msdn.microsoft.com/en-us/library/… Is it wrong?
CraftyFella
Also it works fine on development and our testing environment, which is very odd!
CraftyFella
MaxRequestLength is in kilobytes.
OrionRobillard
+1  A: 

I don't see that this could be due to the maxRequestLength. The code is in the middle of FileStream.Write, so long past any question of receiving data. Confirm this by looking at Data.Length in the debugger.

Why do you have WebMethod(true)? Try just [WebMethod] and see what happens.

John Saunders
Hi,Yes i've confirmed the server is receiving the data ok. I pass in a check sum in the actual live version, to confirm the received bytes are the same as the bytes past in by the client. I'll try the webMethod suggestion and get back to you. Thanks
CraftyFella
BTW... Just using [webmethod] didn't change anything.
CraftyFella
A: 

WriteAllBytes loads the entire file into RAM before writing it to disk. You're running out of memory.

+1  A: 

I know you are not reaching this size of file but also be aware that File.WriteAllBytes has a limit of 64mb when writing to network paths - see this connect issue

Richard
Thanks.. I'll try their suggested workaround and get back to you..string path = "\\server\share\myfile.pdf";string tempPath = Path.GetTempFileName() + "." + Path.GetExtension(path);File.WriteAllBytes(tempPath, file);File.Move(tempPath, path); As i'd love to be able to get the answer to this issue. :-)Dave
CraftyFella