Basically, I need to set up a real simple web service to deliver a zip file,
and a real simple Windows app to capture it and write it to the disk. My
problem now is writing it to the disk. I can do it without errors using the
code below, but the resultant file is larger than the original, and is
corrupt. I suspect it's due to some impedance mismatch between the
webservice delivering byte(), and an inappropriate use of streamreader in
the windows app. If anything jumps out at you, I'd sure appreciate the
guidance. Thanks.
Joe
Here's the simplified web service:
_
Public Function RetrieveZip() As Byte()
Dim path As String = "C:\test.zip"
Dim bindata() As Byte = File.ReadAllBytes(path)
Return bindata
End Function
And here's the windows app:
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim httpRequest2 As HttpWebRequest =
WebRequest.Create("http://localhost:42944/WebSite1/Service.asmx/RetrieveZip")
Dim lFileLength As Long - 94038
Dim httpResponse2 As HttpWebResponse
Dim sr As IO.StreamReader
Dim strFileDest As String = "C:\temp\test.zip"
Dim bytesRead As Integer = 0
httpRequest2.Method = "Post"
httpRequest2.ContentLength = lFileLength
httpRequest2.ContentType = "application/zip"
httpResponse2 = httpRequest2.GetResponse()
Seems to work find up to here, I think
sr = New StreamReader(httpResponse2.GetResponseStream())
Dim stream_writer As New IO.StreamWriter(strFileDest, False)
stream_writer.Write(sr.ReadToEnd())
stream_writer.Close()
TextBox1.Text = "Finished!"
End Sub
End Class
Archived from group: microsoft>public>vb>syntax