Hi
My application consists of a database, WebService and web application. The
web application reads and writes data to the database via the WebService. I
also want to be able to upload/download files via the WebService because my
WebService handles security.
My question is - how can this best be done? After some googleing a solution
I found was to stream bytes in a method like this:
<WebMethod()> _
Public Function UploadFile(ByVal docbinaryarray As Byte(), ByVal docname
As String) As Boolean
Dim strdocPath As String
strdocPath = "C:\Inetpub\wwwroot\FileUploadDownloadSvc\temp\" +
docname
Dim objfilestream = New System.IO.FileStream(strdocPath,
System.IO.FileMode.Create, System.IO.FileAccess.ReadWrite)
objfilestream.Write(docbinaryarray, 0, docbinaryarray.Length)
objfilestream.Close()
Return True
End Function
Will this handle large files? Is this the best way to do it or is there
another better solution?
Many thanks!
Julia Beresford
Peter Kelcey - 30 Nov 2005 17:55 GMT
Julia
There are a number of options you can use for transmitting large
amounts of binary data. The solution you've listed (known as
base-64-encoding) is an okay solution. Your data will be transmitted
properly and it will be contained within your SOAP envelope (meaning
that you can use things like WS-Security) if you want. It is a highly
interoperable and composable solution. The downside is that it isn't a
very efficient solution. Base 64 encoding of your binary data results
in it bloating up anywhere from 33-100% during the transmission. If you
are planning on transmitting large amounts of data quickly, then you
might potentially run into some performance and latency issues.
There are some other options out there such as DIME and SOAP with
Attachments (SwA). But both of these have issues of their own. The
solution I currently recommend people looking closely at is using
Message Transmission Optimization Mechanism (MTOM). MTOM comes with the
Web Services Enhancements 3.0 from Microsoft. It's a really easy to use
technology that avoids a lot of the pitfalls of the other options.
I've written a brief overview of the different solutions and
specifically MTOM. You can check it out at
http://peterkelcey.com/pk_blog/index.php?m=20051119
I'd also suggest checking out the following article on MSDN
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnwebsrv/html/o
paquedata.asp
Hope that helps
Peter Kelcey