473,800 Members | 2,518 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Met hod = "Post"
httpRequest.Con tentType = "text/xml; charset=utf-8"
httpResponse = httpRequest.Get Response()
Dimsr As NewStreamReader (httpResponse.G etResponseStrea m())
strStatus = sr.ReadToEnd()
sr.Close()
httpResponse.Cl ose()

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

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

httpRequest2.Me thod = "Post"
httpRequest2.Co ntentLength = lFileLength
httpRequest2.Co ntentType = "applicatio n/x-zip-compressed"
httpResponse2 = httpRequest2.Ge tResponse()' 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.We bService

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

Dimbindata() As Byte= File.ReadAllByt es(path)
Returnbindata
EndFunction

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

lFileSize = FileLen(path)

strFileSize = CStr(lFileSize)

ReturnstrFileSi ze
EndFunction
End Class
Aug 10 '07 #1
4 2773
"Rootworker " <ma******@rootw erx.comwrote in message
news:13******** *****@corp.supe rnews.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.Met hod = "Post"
httpRequest.Con tentType = "text/xml; charset=utf-8"
httpResponse = httpRequest.Get Response()
Dimsr As NewStreamReader (httpResponse.G etResponseStrea m())
strStatus = sr.ReadToEnd()
sr.Close()
httpResponse.Cl ose()

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

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

httpRequest2.Me thod = "Post"
httpRequest2.Co ntentLength = lFileLength
httpRequest2.Co ntentType = "applicatio n/x-zip-compressed"
httpResponse2 = httpRequest2.Ge tResponse()' 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\R andD\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?
ReturnstrFileSi ze
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(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button1.Click

Dim httpRequest2 As HttpWebRequest =
WebRequest.Crea te("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.z ip"

Dim myString As String

Dim inBuf(100000) As Char

Dim bytesRead As Integer = 0

Dim fstr As New FileStream(strF ileDest, FileMode.OpenOr Create,
FileAccess.Writ e)

httpRequest2.Me thod = "Post"

httpRequest2.Co ntentLength = lFileLength

httpRequest2.Co ntentType = "applicatio n/zip"

httpResponse2 = httpRequest2.Ge tResponse() ' hangs here.

sr = New StreamReader(ht tpResponse2.Get ResponseStream( ))

myString = sr.ReadToEnd()

TextBox1.Text = myString

End Sub

End Class
Aug 12 '07 #3
"Rootworker " <ma******@rootw erx.comwrote in news:13bu7irq34 im08
@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
2410
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 will be returned as DataSet. Now, here's the problem. On .NET Framework 1.1, if any rows in the dataset returned contain errors (marked by calling the SetColumnError() method or
0
1011
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 with third party api. So I am using a .h file and a .lib file that comes with this api. I've placed the actual .lib file in a bin directory that I created with the project.
4
1342
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 like to be able to configurate them all from 1 file.
2
4222
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 xml data to a SQL table and finally send back an XML confirmation file. I have researched several samples and can not find any that is even close to this task. Any help would be greatly appreciated.
0
945
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 (windows 2000). Line 256: <add assembly="System.EnterpriseServices, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/> Line 257: <add assembly="System.Web.Mobile, Version=1.0.5000.0,...
0
1093
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 got the same error when I access the webservice through IE directly. The following is the error message: line 196£º <add assembly="System.EnterpriseServices, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
3
1513
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 user to download the DevTools, but thos development tools are in VB6.0 and Java, I do not understand that how do I post my request to UPS and get response through ASP.NET 1.1. It has a webservice named LandedCost.wsdl. I think it is a java based...
0
1138
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 i set it to 1kB i get random exceptions ( cannot connect to webservice ). As a result i cannot download whole file. What i can download is about half of the file ( 18MB ) with moreless 10 exceptions. When i catch exception, then program tries to...
5
2941
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 admit I am rather confused and frustrated. That being said, I'd like some direction in how exactly I'm supposed to accomplish this. Thanks very much, JK
0
9690
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10501
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10273
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9085
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7574
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6811
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5469
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5603
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4149
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.