We help IT Professionals succeed at work.

How do I send large file via Web Service

I want to send some videos up to my web server, but it seems that the way I'm sending them now has a limitation of 3072k (because any file larger than that fails).

Below is the code that I call from and to.  This all works fine when it comes any other file (under the 3072k file size).

The ex.message propert when the error occurs (denoted in the code snippet) is as follows:  The underlying connection was closed: An unexpected error occurred on a receive.

So, what I need is code to send a file, and then how to receive it back on the web service side.
'*** NOTE, I DIDN'T DECLARE EVERYTHING I USED BECAUSE I JUST COPIED AND PASTED THE IMPORTANT BITS ***
 
'*** ON THE WEB APP ***
<WebMethod()> _
 Public Function SendImage(ByVal aoImageByte() As Byte, ByVal asFilename As String) As String
	Dim sRet as String = ""
	Dim oImage As System.Drawing.Image = Nothing
 
	Try
		Dim oFS As IO.FileStream
		Try
			oFS = File.OpenWrite(sUploadFolder & "\" & asFilename)
			Try
				oFS.Write(aoImageByte, 0, aoImageByte.Length)
			Catch ex As Exception
				sRet = "* ERROR: " & ex.Message
			End Try
 
			oFS.Close() : oFS.Dispose() : oFS = Nothing
	Catch ex As Exception
		sRet = "* ERROR: " & ex.Message
	End Try
 
	Return sRet
End Function
 
'*** SUB BELOW IS WHAT I USE TO CALL THE WEB REFERENCE IN A VB.NET APP ***
 
'*** WEB REFERENCE ***
Dim coProcessImage As New WRProcessImages.ProcessImages
 
Private Sub SendFile
	Dim oFS As FileStream, sRet as String = ""
	
	Try
		oFS = File.OpenRead(oMyImage.Folder & "\" & oMyImage.Filename)
 
		Dim bImageByte(oFS.Length - 1) As Byte
 
		oFS.Read(bImageByte, 0, oFS.Length)
 
		'**** HERE IS WHERE I GET THE EXCEPTION EVERY TIME IF FILE SIZE IS OVER 3072k
		Try
			sRet = coProcessImage.SendImage(bImageByte, oMyImage.Filename, 0, "N")
		Catch ex As Exception
			sRet = "WEB SERVICE ERROR: " & sRet
		End Try
 
		bImageByte = Nothing
	Catch ex As Exception
		sRet = "COULD NOT OPEN VIDEO FILE.  FILENAME: " & oMyImage.Filename
	End Try
 
	oFS = Nothing
End Sub

Open in new window

Comment
Watch Question

CEO / CTO
Top Expert 2005
Commented:
Change the web.config or machine.config to increase the upload limit on iis.
Check this article.
http://www.c-sharpcorner.com/UploadFile/scottlysle/UploadwithCSharpWS05032007121259PM/UploadwithCSharpWS.aspx
You might be runing into a File System limitation.  AKA NTFS file size limit vs Fat32 file size limit.

Author

Commented:
Thanks!

Author

Commented:
That was exactly it.  I added the snippet below to the web.config file and it worked like a charm.

Thanks!
	<system.web>
		<httpRuntime maxRequestLength="250000"/>

Open in new window

Explore More ContentExplore courses, solutions, and other research materials related to this topic.