Archive for June, 2009

WebRequest and Unable to read data from the transport connection Error

Tuesday, June 30th, 2009 | Code | Comments Off

Weird thing just happened, a Windows Service responsible for grabbing some data form an online XML source, suddenly stopped working after two years of continuous functioning…

First I thought that the remote XML had changed somehow but the service returned
“Unable to read data from the transport connection: The connection was closed.”

The code that connected to the remote XML was pretty low-tech:

WebRequest wRq = WebRequest.Create(remoteUri);
WebResponse wRs = wRq.GetResponse();
Stream strm = wRs.GetResponseStream();
StreamReader sr = new StreamReader(strm, Encoding.UTF7);
XmlDocument xDoc = new XmlDocument();
xDoc.Load(strm);
//IT WAS CRASHING HERE

After some research it seems that the remote side closes the connection prior to it being finished…
I had to change the code as follows and the problem was solved:


CookieContainer CC = new CookieContainer();
HttpWebRequest wRq = (HttpWebRequest)WebRequest.Create(remoteUri);
wRq.Proxy = null;
wRq.UseDefaultCredentials = true;
wRq.KeepAlive = false; //THIS DOES THE TRICK
wRq.ProtocolVersion = HttpVersion.Version10; // THIS DOES THE TRICK
wRq.CookieContainer = CC;
WebResponse wRs = wRq.GetResponse();
Stream strm = wRs.GetResponseStream();
StreamReader sr = new StreamReader(strm, Encoding.UTF7);
XmlDocument xDoc = new XmlDocument();
xDoc.Load(strm);
//NO LONGER CRASHING HERE

Windows Mobile Tip - storage card 2

Tuesday, June 16th, 2009 | General | No Comments

If you have a Windows Mobile 6 device, you use it with a storage card for a period of time and for some reason (I don’t know - your HTC DUAL TOUCH screen stops working and you don’t want the service guys to copy the content of your card) you start it without a storage card then reinsert the initial card, all the programs installed on that card will stop working ( and NO the card is not broken) because Windows Mobile already has a Storage Card folder and has created a Storage Card 2 folder although it’s the same card…

So the solution is to enter the windows explorer and rename the Storage card folder into Storage card something then do a reboot of the device…

Wasn’t it smarter if they have created a checksum on the card, so when you would insert cards the link between installed programs and card would be maintained trough that checksum?