msvisual.com Forum Index
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Writing stream from webservice to file?

 
Post new topic   Reply to topic    msvisual.com Forum Index -> VB Syntax
Author Message
Rootworker



Joined: 04 Oct 2007
Posts: 1

PostPosted: Sun Aug 12, 2007 6:34 pm    Post subject: Writing stream from webservice to file? Reply with quote

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
Back to top
View user's profile Send private message
Jeff Johnson



Joined: 04 Oct 2007
Posts: 1327

PostPosted: Mon Aug 13, 2007 1:17 pm    Post subject: Re: Writing stream from webservice to file? Reply with quote

> _

[Canned response]
This is a VB "classic" newsgroup. Questions about VB.NET (including VB 2005
and VB Express, which have dropped .NET from their names) are off-topic
here.

Please ask .NET questions in newsgroups with "dotnet" in their names. The
*.vb.* groups are for VB6 and earlier. If you don't see the *.dotnet.*
groups on your news server, connect directly to the Microsoft server:
msnews.microsoft.com.

For questions specific to the VB.NET language, use this group:
microsoft.public.dotnet.languages.vb

Please note that things like controls and data access, which have their own
subgroups in the Classic VB hierarchy, are not language-specific in .NET, so
you should look for groups like these:
microsoft.public.dotnet.framework.windowsforms.controls
microsoft.public.dotnet.framework.adonet
(Note that "vb" is not present in the group name.)

Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    msvisual.com Forum Index -> VB Syntax All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group