Quantcast
Channel: WCF, ASMX and other Web Services
Viewing all articles
Browse latest Browse all 555

Read large binary file into byte array - File.ReadAllBytes throws 'System.OutOfMemoryException'

$
0
0

Running on Windows Server 2003, IIS 6.0, Visual Studio 2010, .Net Framework 3.5

The web service is throwing a "System.OutOfMemoryException" whenever it tries to read a file large binary file (> 80 Meg).

To make troubleshooting this issue easier, I have separated out the code into a simple web service with only one call
GetByteArrayFromFile which reads a file and returns a byte array.

It consistently throws the 'Out of Memory' exception with files larger than 80 Meg.

Are there any steps I can take to resolve this issue?

'**********************************************************
'Web Service Call
Imports System.Web.Services, System.Web.Services.Protocols, System.ComponentModel

<System.Web.Services.WebService(Description:="Testing", _    
  Namespace:="http://Testing.org/")> _
  <System.Web.Services.WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
  <ToolboxItem(False)> _
Public Class ProcSvcs   Inherits System.Web.Services.WebService

<WebMethod(Description:="Byte array from File")> _  
Public Function GetByteArrayFromFile(ByVal PathFName As String) As Byte()    
Try      
  Dim Content() As Byte = System.IO.File.ReadAllBytes(path:=PathFName)      
  Return Content    
Catch ex As Exception      
   Throw New Exception(ex.Message)    
End Try  
End Function

End Class

 


Viewing all articles
Browse latest Browse all 555

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>