473,231 Members | 1,498 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,231 software developers and data experts.

HTTPWebRequest error | Transport connection related

I am working on a VB .net application which accesses a Java Servlet.
This servlet returns a binary stream that is written onto a PDF and then
this file is printed. Even though this file is downloaded and printed on most
environments, it fails to do so on one of the environments with the following
error:
"Unable to read data from the transport connection."

Also to be noted is the fact that when this servlet is hit from a different
geography, the response is obtained in perfect order and the file also gets
generated. Here's the sample code that does it:

Dim req As HttpWebRequest
Dim res As HttpWebResponse
req = WebRequest.Create("https://**********")
req.Method = "GET"
req.CookieContainer = New CookieContainer
req.CookieContainer.Add(ccContainer.GetCookies(req .RequestUri))
req.ContentType = "text/xml"
' Send the text to the webserver
res = req.GetResponse()
Dim Cook As Cookie
For Each Cook In res.Cookies
Me.ccContainer.Add(Cook)
'MsgBox(Cook.Name)
Next
' Wrap the response stream with a text-based reader
Dim sr As BinaryReader = New BinaryReader(res.GetResponseStream())
' Read the returned text into a textbox
Dim bWriter As New BinaryWriter(File.OpenWrite("temp.pdf"))
bWriter.Write(sr.ReadBytes(99999999))
bWriter.Close()

It seems to me that the problem creeps up when you're trying to access the
response stream to associate with the binary reader. However, I have not been
able to validate this.

Any pointers to this are gladly appreciated.

Regards,
Sanjeev

Jan 24 '06 #1
3 1909
Hello Sanjeev,
I am working on a VB .net application which accesses a Java Servlet.
This servlet returns a binary stream that is written onto a PDF and
then
this file is printed. Even though this file is downloaded and printed
on most
environments, it fails to do so on one of the environments with the
following
error:
"Unable to read data from the transport connection."
Also to be noted is the fact that when this servlet is hit from a
different geography, the response is obtained in perfect order and the
file also gets generated. Here's the sample code that does it:

Dim req As HttpWebRequest
Dim res As HttpWebResponse
req = WebRequest.Create("https://**********")
req.Method = "GET"
req.CookieContainer = New CookieContainer
req.CookieContainer.Add(ccContainer.GetCookies(req .RequestUri))
req.ContentType = "text/xml"
' Send the text to the webserver
res = req.GetResponse()
Dim Cook As Cookie
For Each Cook In res.Cookies
Me.ccContainer.Add(Cook)
'MsgBox(Cook.Name)
Next
' Wrap the response stream with a text-based reader
Dim sr As BinaryReader = New BinaryReader(res.GetResponseStream())
' Read the returned text into a textbox
Dim bWriter As New BinaryWriter(File.OpenWrite("temp.pdf"))
bWriter.Write(sr.ReadBytes(99999999))
bWriter.Close()
It seems to me that the problem creeps up when you're trying to access
the response stream to associate with the binary reader. However, I
have not been able to validate this.


There's no point in using a BinaryReader to read raw bytes. Simply read from
the response stream until no more input is available:

using(Stream responseStream = response.GetResponseStream()) {
byte[] buffer = new byte[0x1000];
int bytes;
while((bytes = responseStream.Read(buffer, 0, buffer.Length)) > 0) {
// Do something with buffer, e.g. write to FileStream
}
}

Cheers,
--
Joerg Jooss
ne********@joergjooss.de
Jan 24 '06 #2
Hi Joerg,
Thanx for such a prompt response.
I found a work around of the problem by specifying the ip andp port
explicitely in my browsers exceptions: 10.xx.xx.xx:7001.
Whereas if we directly access the servlet from a web browser we need not
specify such port settings.
Could you please tell why is it so and what tweak i need to apply in my code
to avoid these additional settings.

Regards,
Sanjeev K Purohit

"Joerg Jooss" wrote:
Hello Sanjeev,
I am working on a VB .net application which accesses a Java Servlet.
This servlet returns a binary stream that is written onto a PDF and
then
this file is printed. Even though this file is downloaded and printed
on most
environments, it fails to do so on one of the environments with the
following
error:
"Unable to read data from the transport connection."
Also to be noted is the fact that when this servlet is hit from a
different geography, the response is obtained in perfect order and the
file also gets generated. Here's the sample code that does it:

Dim req As HttpWebRequest
Dim res As HttpWebResponse
req = WebRequest.Create("https://**********")
req.Method = "GET"
req.CookieContainer = New CookieContainer
req.CookieContainer.Add(ccContainer.GetCookies(req .RequestUri))
req.ContentType = "text/xml"
' Send the text to the webserver
res = req.GetResponse()
Dim Cook As Cookie
For Each Cook In res.Cookies
Me.ccContainer.Add(Cook)
'MsgBox(Cook.Name)
Next
' Wrap the response stream with a text-based reader
Dim sr As BinaryReader = New BinaryReader(res.GetResponseStream())
' Read the returned text into a textbox
Dim bWriter As New BinaryWriter(File.OpenWrite("temp.pdf"))
bWriter.Write(sr.ReadBytes(99999999))
bWriter.Close()
It seems to me that the problem creeps up when you're trying to access
the response stream to associate with the binary reader. However, I
have not been able to validate this.


There's no point in using a BinaryReader to read raw bytes. Simply read from
the response stream until no more input is available:

using(Stream responseStream = response.GetResponseStream()) {
byte[] buffer = new byte[0x1000];
int bytes;
while((bytes = responseStream.Read(buffer, 0, buffer.Length)) > 0) {
// Do something with buffer, e.g. write to FileStream
}
}

Cheers,
--
Joerg Jooss
ne********@joergjooss.de

Jan 30 '06 #3
Hello Sanjeev,
Hi Joerg,
Thanx for such a prompt response.
I found a work around of the problem by specifying the ip andp port
explicitely in my browsers exceptions: 10.xx.xx.xx:7001.
Whereas if we directly access the servlet from a web browser we need
not
specify such port settings.
Could you please tell why is it so and what tweak i need to apply in
my code
to avoid these additional settings.
Regards,


What do you mean by "browser exceptions"? IP adresses that are not to be
proxied?

Cheers,
--
Joerg Jooss
ne********@joergjooss.de
Jan 30 '06 #4

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

Similar topics

4
by: Mike Dole | last post by:
I'm working on a client - server application based on the 'How to Sockets Server and How to Sockets Client' code from the Visual Basic ..NET Resource Kit. Since I want to be able to send 'big...
0
by: Steve - DND | last post by:
We are continually receiving timeout, and "Unable to write data to the transport connection" errors while using the System.Net.HttpWebRequest class from an ASP.Net web page. Below are the two...
1
by: Muscha | last post by:
Hello, Every now and then my application throw this exception: "Unable to read data from the transport connection" And when I break into the Visual Studio, the thread where it failed has...
2
by: Keith Avery | last post by:
We have an ASP.NET application. This is loading data using XML from another ASP web site. It all works fine for small XML data files. For larger XML data file being streamed from the ASP web...
0
by: steve.edison | last post by:
I have an application that pulls an xml file from another site that is around 4 megs in size and posts it to a webservice for processing. In our development environment it works fine. However, in...
0
by: Brent | last post by:
After six months flawless operation, I'm suddenly getting this error: "Unable to read data from the transport connection." The code* hasn't changed, and from what I can see, neither have the IP...
1
by: Terrance | last post by:
I'm trying to create a small messenger program that uses the tcpclient and tcplistenter objects. When I start the application and run the thread that fires the tcplistener; once the client sends...
0
by: Buddy Home | last post by:
Hello, I'm trying to upload a file programatically and occasionally I get the following error message. Unable to write data to the transport connection: An established connection was aborted...
0
by: Paul H | last post by:
I have the following code running against the compact framework: using System; using System.Data; using System.Net; using System.IO; using System.Text; namespace WebSample {
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...

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.