Web Service?

C

Charles A. Lackman

Hello,

Is there a way to Write a file to a stream using a web service? If so How?

Any Help or Suggestions will be greatly appreciated.

Thanks,
Chuck
 
G

Guest

This is a webmethod that takes a file and convert it back out to a Binary Stream

<WebMethod()> _
Public Function ReadFileToStream() As Byte()
Dim fs As FileStream

Try
' Read file and return contents
Dim serverPath As String = "C:\Inetpub\wwwroot\postinfo.html"
fs = File.Open(serverPath, FileMode.Open, FileAccess.Read)

Dim lngLen As Long = fs.Length
Dim abytBuffer(CInt(lngLen - 1)) As Byte
fs.Read(abytBuffer, 0, CInt(lngLen))
Return abytBuffer

Finally
' Make sure that file stream is
' closed even if an error occurs.
fs.Close()
End Try
End Function

Hope this helps
 
C

Charles A. Lackman

Hello and Thank you for your response,

I have noticed that when this code is implemented it does not cause the
client computer to open a download dialogbox. I am assuming that I have to
implement code to receive the file then write it to the clients computer.
Is this correct. The Web Service is being called from a Desktop
Application. I am having a struggle trying to implement this.

Client Computer (Desktop Computer)

fs = New IO.FileStream("C:\Me.wma", IO.FileMode.Create, IO.FileAccess.Write)
Dim BW As New IO.BinaryWriter(fs)
Dim leng As Integer = fs.Length
Dim abytBuffer(CInt(leng - 1)) As Byte
fs.Write(abytBuffer, 0, CInt(leng))
' This causes the file to be 0 in length


Dim serverPath As String = "C:\Test1.WMA"
fs = New IO.FileStream(TheService.StartDownload, IO.FileMode.OpenOrCreate)
Dim BW As New IO.BinaryWriter(fs)
Dim AByte() As Byte = TheService.StartDownload() 'Your Code implemented on
the service
Dim AByte1 As Byte
For Each AByte1 In AByte
bw.write(Abyte1)
next
'This Causes the File to write Gigs and Gigs of data to the file Test1.WMA

Thanks again for your assistance,
Chuck
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top