473,394 Members | 1,852 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

webservice to download a file - need help please.

I have two simple web services, as shown below. One returns the file size of
a test file, and the second the file itself. I can successfully recover the
file size using the following code:\

httpRequest.Method = "Post"
httpRequest.ContentType = "text/xml; charset=utf-8"
httpResponse = httpRequest.GetResponse()
Dimsr As NewStreamReader(httpResponse.GetResponseStream())
strStatus = sr.ReadToEnd()
sr.Close()
httpResponse.Close()

However, when I try to download the file itself, using the following code,
the app just hangs:

DimhttpRequest2 As HttpWebRequest =
WebRequest.Create("http://localhost:1995/webSvs/Service.asmx/RetrieveZip")

httpRequest2.Method = "Post"
httpRequest2.ContentLength = lFileLength
httpRequest2.ContentType = "application/x-zip-compressed"
httpResponse2 = httpRequest2.GetResponse()' hangs here.
Any suggestion how I can retrieve this zip file and write it to my local
disk? Thanks.

Joe

Here are the web services themselves:

Public ClassService
InheritsSystem.Web.Services.WebService

<WebMethod()_
PublicFunction RetrieveZip() As Byte()
Dimpath As String=
"U:\-CVS-\Painless.NET\RandD\webSvs\App_Code\test.zip"

Dimbindata() As Byte= File.ReadAllBytes(path)
Returnbindata
EndFunction

<WebMethod()_
PublicFunction RetrieveZipSize() As String
Dimpath As String=
"U:\-CVS-\Painless.NET\RandD\webSvs\App_Code\test.zip"
DimlFileSize As Long
DimstrFileSize As String

lFileSize = FileLen(path)

strFileSize = CStr(lFileSize)

ReturnstrFileSize
EndFunction
End Class
Aug 10 '07 #1
4 2756
"Rootworker" <ma******@rootwerx.comwrote in message
news:13*************@corp.supernews.com...
>I have two simple web services, as shown below. One returns the file size
of a test file, and the second the file itself. I can successfully recover
the file size using the following code:\

httpRequest.Method = "Post"
httpRequest.ContentType = "text/xml; charset=utf-8"
httpResponse = httpRequest.GetResponse()
Dimsr As NewStreamReader(httpResponse.GetResponseStream())
strStatus = sr.ReadToEnd()
sr.Close()
httpResponse.Close()

However, when I try to download the file itself, using the following code,
the app just hangs:

DimhttpRequest2 As HttpWebRequest =
WebRequest.Create("http://localhost:1995/webSvs/Service.asmx/RetrieveZip")

httpRequest2.Method = "Post"
httpRequest2.ContentLength = lFileLength
httpRequest2.ContentType = "application/x-zip-compressed"
httpResponse2 = httpRequest2.GetResponse()' hangs here.
Any suggestion how I can retrieve this zip file and write it to my local
disk? Thanks.
First, is there a reason you used HttpWebRequest instead of building a
client using Add Web Reference?
....
<WebMethod()_
PublicFunction RetrieveZipSize() As String
Dimpath As String=
"U:\-CVS-\Painless.NET\RandD\webSvs\App_Code\test.zip"
DimlFileSize As Long
DimstrFileSize As String

lFileSize = FileLen(path)

strFileSize = CStr(lFileSize)
Why not just return the size as a Long instead of converting to string?
ReturnstrFileSize
EndFunction
End Class
--
John Saunders [MVP]

Aug 11 '07 #2
First, is there a reason you used HttpWebRequest instead of building a
client using Add Web Reference?
Uhh -- that was the first example I was able to find online -- I really
don't have clue 1 what I'm doing.
Why not just return the size as a Long instead of converting to string?
Oh --that was just a temporary expedient -- I thought it might be easier to
read. My intent is to change to returning it as a long as soon as I get the
rest working.

As it stands now, I've almost got things working -- I can retrieve the file
as a string. Now I need to know how to turn it into a file -- any pointers?
Thanks so much!

Here's my code in progress:

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

Dim httpResponse2 As HttpWebResponse

Dim sr As IO.StreamReader

Dim strFileDest As String = "e:\temp\temp.zip"

Dim myString As String

Dim inBuf(100000) As Char

Dim bytesRead As Integer = 0

Dim fstr As New FileStream(strFileDest, FileMode.OpenOrCreate,
FileAccess.Write)

httpRequest2.Method = "Post"

httpRequest2.ContentLength = lFileLength

httpRequest2.ContentType = "application/zip"

httpResponse2 = httpRequest2.GetResponse() ' hangs here.

sr = New StreamReader(httpResponse2.GetResponseStream())

myString = sr.ReadToEnd()

TextBox1.Text = myString

End Sub

End Class
Aug 12 '07 #3
"Rootworker" <ma******@rootwerx.comwrote in news:13bu7irq34im08
@corp.supernews.com:
>First, is there a reason you used HttpWebRequest instead of building a
client using Add Web Reference?

Uhh -- that was the first example I was able to find online -- I really
don't have clue 1 what I'm doing.
Have you looked at MTOM? It's part of Microsoft's Web Service Enhancement
Pack - let's you transfer large files over web services:

http://www.codeproject.com/soap/MTOMWebServices.asp
Aug 12 '07 #4
Thanks -- I'll check that out.

Joe
Have you looked at MTOM? It's part of Microsoft's Web Service Enhancement
Pack - let's you transfer large files over web services:

http://www.codeproject.com/soap/MTOMWebServices.asp

Aug 13 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Programatix | last post by:
Hi, I'm working on a project which includes XML WebServices and Windows Form application. The Windows Form application will call the XML WebServices to retrieve data from database. The data...
0
by: Sharon McCarty | last post by:
Hi Everyone, I'm creating a webservice that's written in C++. So, I'm using the wizard by creating a c++ project using the template, ASP.net Web Service. I am trying to make method calls...
4
by: Søren Reinke | last post by:
Hi there I am having a little problem. At the company i work in, we are working on a bunch of applications for a server, and also webservices and aspx pages. The main problem is i would...
2
by: AllenM | last post by:
I have a project that requires an XML webservice that will receive an xml file. The webservice will need to read the XML file, download a pdf file from a URL stored in the XML file then store the...
0
by: anders.henriksen | last post by:
Hi I'm trying to communicate between a tird party system to my webservice and I get the following error message. The third party system (called envox) and my webservice are on the same server...
0
by: Standist | last post by:
vs.net 2003 I create a webservice using vc.net.In the webservice invoked a method in a dll from third party. I compile and link the program without any error.But I got a error when I debug it,I...
3
by: Ather Ali Shaikh | last post by:
Hello all, I am supposed to develop an e-commerce application integrated with UPS Courier services to calculate the cost of shipment of a products. I have UPS account number also have register a...
0
by: djp | last post by:
Hi I have a weird situation which i don't understand. I have simple WebService that sends file to Client. When i set chunk size to 16 kB file is received without any exceptions... However when...
5
by: Jonathan Kay | last post by:
Hi, I'd like to my WCF webservice to work both on SSL and without. Unfortunately searching has led to dead ends, references to changes that only work on the old previous beta versions and I...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.