[ACCEPTED]-How do I upload large (> 25MB) files to a web service?-large-file-upload
In addition to the httpRuntime/maxRequestLength 6 mentioned in the question, it looks like 5 there is an additional item that can be 4 added to the web service's web.config file 3 to permit large file transfers.
<system.webServer> <security> <requestFiltering> <requestLimits maxAllowedContentLength="2000000000" /> </requestFiltering> </security> </system.webServer>
This appears 2 to enable larger files to be uploaded via 1 web services.
You should keep in mind that web services 18 aren't primarily designed as file transfer 17 mechanisms. Any purpose-designed file transfer 16 protocol will likely do a better job than 15 a web service. For instance, such protocols 14 are more likely to deal with error recovery, partial 13 uploads, etc.
However, if you're going to 12 use web services for this purpose in .NET, you 11 should use WCF, if at all possible. Among 10 other benefits, WCF handles streaming, and 9 will therefore be a lot more efficient in 8 terms of memory usage. I'm concerned that 7 if you follow the two (accurate) suggestions 6 above, your next result will be "out of 5 memory or resources" exceptions, as the 4 old ASMX technology tries to load your entire 3 25MB file into memory at once. In fact, it 2 may have several copies in memory at the 1 same time!
If I was stuck having to use web services 7 and needed to support very large files I 6 would look at implementing a system that 5 allows you to upload files in pieces.
- ticketId GetTicket(size)
- UploadData(ticketId, byte payload) (this can be called as many times as you want)
This 4 would allow you to chunk up the big uploads, and 3 not hold too much data in memory. The disadvantage 2 is that you are still using a fairly inefficient 1 transport mechanism.
Just to add information to people googling 4 this web.config:
C:\Program Files\Common 3 Files\Microsoft Shared\Web Server Extensions\12\ISAPI
<location path="Copy.asmx"> <!-- Name of you asmx --> <system.webServer> <security> <requestFiltering> <requestLimits maxAllowedContentLength="104857600"/> <!-- 100 megs --> </requestFiltering> </security> </system.webServer> </location>
This 2 solved our problem after troubleshooting 1 this issue for quite som time.
If you're set on using Web Services to move 18 around files I would at least consider using 17 WS-Attachment / DIME attachments. The primary 16 problem with sending byte's over web services 15 is that they get put in the SOAP body which 14 is gets encoded as a base 64 string. Encoding 13 files like this grows the size of the file by as much as two thirds 12 in the soap body (ie. a 6 MB file becomes 11 a 9 MB file over the wire).
It's likely that 10 your 25 MB upload is turning into HUGE soap 9 envelopes.
I'd strongly suggest reading this. Which might 8 get you into DIME.
Here's an excerpt.
Microsoft's 7 WSE Toolkit allows large attachments to 6 be sent along with a Web service method 5 using the DIME and WS-Attachments standards. We'll examine 4 these standards and why they are more 3 efficient than sending large amounts of 2 binary data in a Web service call through 1 other common means.
Hope that helps!
maxRequestLength is in KB, not bytes. This 6 should give you a 30 MB limit within a 4-minute 5 timeout window.
<httpRuntime executionTimeout="240" maxRequestLength="30000" />
Having numbers that are too 4 high may be actually preventing your values 3 from being applied. I think I ran into this a 2 few years ago when I thought it was a byte 1 limit (vague memory).
This doesn't specifically answer you question, but 4 what I've done in the past is use WCF to 3 transfer file names/paths/listings, but 2 then use an FTP library to transfer the 1 file via FTP.
this worked for me:
<binding name="uploadFilesBasicHttpBinding" maxReceivedMessageSize="2147483647" maxBufferSize="2147483647" maxBufferPoolSize="2147483647" receiveTimeout="00:10:10" sendTimeout="00:10:00" openTimeout="00:10:00" closeTimeout="00:10:00"> <readerQuotas maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxDepth="2147483647" maxNameTableCharCount="2147483647" maxStringContentLength="2147483647"/> <security mode="TransportWithMessageCredential"> <message clientCredentialType="UserName"/> </security> </binding>
More Related questions