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 3 1915
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
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
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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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
{
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
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...
|
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...
|
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...
|
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...
|
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,...
|
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...
|
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...
| |