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:   
Related Topics:
Problem with open file in stream object Hi All, My VB6 application need to generate UTF-8 encoded files. I am using stream object with code like this: Set stm = New Stream stm.Open adModeWrite stm.charset = "UTF-8" ............. The open command failed with message "Objec

VB6.0 Writing Image to file I have a form with an Image control containing a jpeg. I'd like to write it to a file (image1.jpg). I've managed to copy it to the clipboard, but can't figure out how to write it to a file (or to simple take the jpg from the image control on my form a

Printing/Writing to a file hello, i'm to a file using the 'print' function in VB6. i.e open #file print #file 'something' close #file the problem i'm having is that after the print function it appends a carriage return at the end. i was wondering if there is anywa

Writing to a Text file Hi I'm trying to read and write to a text file. I have been able to read a file, line by line using the "line Input" method. Writing to a file is more difficult however, since I will need to close the file b/w successive writes. I will need to be able to

Problem writing a file - vb6 Hi folks: I need help figuring out how to write binary files in VB. What is happening is that the file always contains 8 extra bytes at the beginning. I know that filedata contains the correct data - the data is a cabinet file (.CAB) and the header sig o
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