Unable to read data from the transport connection.
-
Tuesday, December 19, 2006 1:57 PM
Hello! I am developing an application for a Windows CE 5.0 device(Symbol MC 3000) and I am trying to send an object[] to a WebMethod on a Web Service.
If the object[] has over 40 items in it, I get this Exception :
[System.Net.WebException] {"Unable to read data from the transport connection."} System.Net.WebException
+ InnerException {"An existing connection was forcibly closed by the remote host"} System.Exception {System.Net.Sockets.SocketException}StackTrace "at System.Net.HttpWebRequest.finishGetResponse()\r\nat System.Net.HttpWebRequest.GetResponse()\r\nat System.Web.Services.Protocols.WebClientProtocol.GetWebResponse()\r\nat System.Web.Services.Protocols.HttpWebClientProtocol.GetWebResponse()\r\nat System.Web.Services.Protocols.SoapHttpClientProtocol.doInvoke()\r\nat System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke()\r\nat
Project1.WSGet.WSget.SetMailLog()\r\nat
Can someone help me with that?
Thanks!
Answers
-
Tuesday, January 23, 2007 7:11 PM
Sounds like the server is closing out the underlying socket on large data. How large are these objects? and is the server code designed to handle more than 40 objects? Potentially the server application is going out of bounds or there is some limit for size on the server configuration that prevents large packets coming off the network.
Thanks,
Sandy
-
Wednesday, March 12, 2008 12:34 PM
Hello.
I've solved the problem by passing smaller objects. I can't remember the size of the objects when I've got this error but by makeing them smaller did the trick!
Hope this helps!
All Replies
-
Tuesday, January 23, 2007 7:11 PM
Sounds like the server is closing out the underlying socket on large data. How large are these objects? and is the server code designed to handle more than 40 objects? Potentially the server application is going out of bounds or there is some limit for size on the server configuration that prevents large packets coming off the network.
Thanks,
Sandy
-
Wednesday, June 06, 2007 4:49 AM
I am having the same problem. The only difference is i am trying to send a very big string....So did you find the solution for that.
Please share it and thank you very much for your help.
-
Wednesday, March 12, 2008 12:28 PMHi,
Hi to all, how can we resolve this problem? Do you have any solutions for this?
Thanks,
Jaypee -
Wednesday, March 12, 2008 12:34 PM
Hello.
I've solved the problem by passing smaller objects. I can't remember the size of the objects when I've got this error but by makeing them smaller did the trick!
Hope this helps!
-
Monday, March 31, 2008 2:27 AM
Hi Eusebui,
I have also resovled this problem. Since http is limited in bytes, I assigned smaller objects per parameter. So, in this process, I send the data per batch.
Regards,
Jaypee- Proposed As Answer by Roberto Pires Wednesday, May 11, 2011 6:14 PM
-
Wednesday, July 16, 2008 3:09 PM
Hi,
The issue I was experiencing (if I remember correctly) was when trying to send data over a GPRS connection to a web service. Intermittently the connection would fail for no obvious reason and the user would be left with a spinning dial and the error "unable to read data from the transport connection"
At the time, we could not find any obvious solutions to this issue and so we attempted to reduce the amount of data we were transferring to see if that helped the matter.
Although this helped to a point, I found out that it wasn't the size of the byte array but instead the time it was taking for the query to execute on the server (the more data, the more time the query was taking to exec)
The request worked over some mobile networks (o2, Vodafone, T-Mobile) but was timing out over Orange as they have a 10 sec request timeout for HTTP.
Hope this helps anyone experiencing the same problem.
Nick Kewney
-
Monday, December 29, 2008 11:16 AM
Hi everybody
few days ago I have solved the same problem !
Yes the one solution can be in reducing the data sent to server (splitting the desired object into smaller parts). This is solution that I also applied twop years ago when I have faced the same problem with long http request (http:// was two long ). But this solution is extremelly complicate and vulnerable for thousand of errors.
Problem presentation:
A month ago, I've created webService that does the same actions on server side. I wanted to send one (custom made) my object that contains all necessary data (e.g. the "Order" object that contains all data about the customer, customer address, dates, etc. as well as all order's items including product codes, quantities, rabats etc. ect). Pretty big object - but an elegant solution. Then I faced (again) the same problem with the same WebException (unable to read data....).
Then I created a test procedure that were passing a simple object (containing simple 3 string properties and one string array (string[]) with 3 values) into the WebService. The testing procedure worked perfectly - over GPRS.
When I tested my "big" object while HandHeld device was connected to the network directly over cradle - there were no problems, everything worked perfeclty. BUT when I wanted to test the same using GPRS connection - I got mentioned error.
Thanks to simple freeware tool "SmartSniff" (available on http://www.nirsoft.net/utils/smsniff.html) I saw strange http request that looked like this:
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema xmlns="http://localhost/ASPORCLNET.PageProcessing"><cpIn>..........................................................................................................
..............................................................................................................................................................................................................
..............................................................................................................................................................................................................
..............................................................................................................................................................................................................
..............................................................................................................................................................................................................
..............................................................................................................................................................................................................
....................................................................g>0</string><string>0</string><string>0</string></spRobniRabat><spOdobrenoRR>
<string>0</string><string>0</string><string>0</string></spOdobrenoRR><spArtikalPSID><string>NISTA</string>
<string>NISTA</string><string>NISTA</string></spArtikalPSID><spArtikalPSSifra><string>NISTA</string><string>NISTA</string>
<string>NISTA</string></spArtikalPSSifra></cpIn><isJC>true</isJC></testCPorudzbenica></soap:Body></soap:Envelope>
As you can see there are bunch of dots in the request. Those dots, viewed in hex are aqtually all zeros. And more strange is that the end of request was correct. My object data should start from tag <cpIn>.
OK, lets go to the explanation:
Problem description:
There is a parameter called MTU (Maximum Transportation Unit) which is part of TCP/IP settings. Since I'm not network engineer, I'll try to explain on my way (for more information you can see the link http://msdn.microsoft.com/en-us/library/ms882717.aspx).
This parameter defines how big packets of data (in bytes) can be used for sending data (requests) over the network. Each web request is splitted into the packets which size is defined by MTU.
Now, the device (which sends request) has (or not) its own value for MTU. On the other hand the GPRS and network has their own MTU value (which is by default 1500).
Now, if device sends some request which is divided into the packets which size is BIGGER than the network's (or GPRS) MTU, the request arrived on the server side looks like the one above (with dots). As I understand, the GPRS cannot "understand" (read) all those packets that oversizes the it's own packets size, and just clears them (set them to zero). All those packets which size is less then GPRS's MTU, come to the server side correctly.
Anyhow, the SOLUTION is - to reduce the MTU value on the HandHeld device to the size which is SMALLER than GPRS's MTU.
On the link: http://msdn.microsoft.com/en-us/library/ms884977.aspx you can see some registry keys with their explanations. I use the MTU registry key and ADDED IT INTO THE registry path HKEY_LOCAL_MACHINE\Comm\Tcpip\Parms (as its written on the mentioned link). I set the value of MTU to the 1300 bytes (in decimal prezentation) or 514 as Hexadecimal presentation.
One more important registry key which is obviously (after testing) MUST to be added is :
EnablePMTUDiscovery (as DWORD) with decimal value set to 0. You need to add this registry key at the same registry path (HKEY_LOCAL_MACHINE\Comm\Tcpip\Parms). I was thinking it is not important, but YES it is important !
After adding mentioned two registry keys, should be good to restart the HandHeld (just warm reset).
When I did it - ALL MY REQUESTS arrived to the server correctly with all the values contained in my big object.
*******************************************************
One more thing : this problem has no any connection with (version of) MS Compact .NET Framework !
At the end I must to thank to my great friend and the "programer giant" Mr. Momir Boskovic, the CEO of Diginaut (Serbia) http://www.diginaut.co.rs for his unselfish help !!!
I hope this will help to lot of people
Regards Petar Nedic (petar.nedic@itm.rs) !- Proposed As Answer by Petar Nedic Monday, December 29, 2008 2:46 PM
-
Wednesday, June 17, 2009 11:20 PM
Please, this is very urgent.
i have a mobile application that access to a web service.
some times it returns the error: (i don’t know what to do)
windows mobile system.net.webexception: unable to read data from the data transport system.net.socket exception: an existing connection was forcibly
-
Thursday, June 18, 2009 7:11 AMRicardo
When you say "some times it returs error", this means that probably you did not set the MTU value (see my post above). I suppose that mostly, your WebServis (ws) returns stream which length is bellow the maximum length that your hh device can accept, lets say, in one piece - which is defined by MTU on device. In some cases the length of ws response is over the maximum length of MTU when device rises mentioned error. When there is no defined MTU on device, the device use some it's own, who knows where and how defined, MTU.
So, setting the MTU on device forces the device to accept responses from server in the blocks. If I can interpret differently, if no MTU set - tends to accept everything in one piece. If there is MTU set, then accepts any response in packets.
Anyhow, setting the MTU as I said above, should not make any problems on device.
One more thing, you should pick up from net application SmartSniff (from link above) and you can investigate what is happenning when you get error. If you see the unexpected termination of ws response, then problem is in MTU.
I hope this was helpful.
Regartds Peter ! -
Thursday, June 18, 2009 9:52 AM
Dear Peter
First of all, many thanks for your quick reply.
How I access to the HKEY_LOCAL_MACHINE in Smart Device ?Can I make a small app to run in all devices that it will change the settings?
Thanks in advance
Ricardo -
Thursday, June 18, 2009 10:33 AMi only need to make this, correct ?
string regName = "\\comm\\Tcpip\\Parms\\";
// Open the base key for the adapter.
RegistryKey tcpipkey = Registry.LocalMachine.OpenSubKey(regName,
true);
tcpipkey.SetValue(
"MTU", "1300");
tcpipkey.SetValue(
"EnablePMTUDiscovery", "0");
-
Thursday, June 18, 2009 2:38 PM
I Peter,
I already set the MTU like you told me, and I’m still getting the same message.
I remember that this bug its happening in a irregular way. The same method and the same data, sometimes works other times not.
Can you help me .
All the best
Ricardo
-
Monday, June 22, 2009 7:46 AM
I Peter,
I already set the MTU like you told me, and I’m still getting the same message.
I remember that this bug its happening in a irregular way. The same method and the same data, sometimes works other times not.
Can you help me .
All the best
Ricardo
Hi Ricardo,
Hm, if you still have problem, then I am not quite smart to give some other suggestions. Mentioned registry keys solved my problem (at 100%). As I see, you set mentioned keys on application level as I did (only I have used some other libraries). Anyhow, I can suggest one more additional check to avoid seting all the time when you start the application in the way:
if(!tcpipkey.ExistsValue("MTU")) {
tcpipkey.SetValue("MTU", "1300");
tcpipkey.Close();
MessageBox("Before continue, You must reset device!");
Application.Exit;
}
For other reg. key add the same check.
Well try this:
1. Change MTU value in both directions: reduce (to e.g. 650) or raise (up to 1500)
2. Have you check what is happening with SmartSniff when you get the error ? This is very helpful tool ! Put it on the server computer, run it (start monitor) and call the procedure from device.
3. Can you give me the example of data when you get the error.
4. Are you using WebService for generation of response ? If not, I would suggest you to do that. Now I am sending over the network complete my objects (created by Webservice) filled out with bunch of data (e.g. the customer object with complete personal data, list of addresses, delivery places and some other informations - everything in one object which is very easy to handle on both sides: server and device).
If you say: "The same method and the same data, sometimes works other times not", then it can be some other problem - the quality of GPRS connection. In my experience (over 2 years of using GPRS with over of 100 agents) sometimes even there is "good" signal, the GPRS transport is almost zero. Personaly I don't think this is cause of your problem (but maybe to check this). Those problems, with GPRS, I have radically reduced by using MTU, but not at all. If you can see the process of exchanging bytes over GPRS (Rx bytes and Tx bytes), check if you have (and how many) Rx bytes when you call the "problematic" procedure. This will give you the picture of device communication over GPRS (beside SmartSniff).
Hm, at this moment, I have this ideas to suggest you.
There is one more way to avoid this, but this is an ugly approach : to make response that will be splited in sequences of strings. This approach I used before I start to use WebServices and MTU. This is so bad approach in term of time spent for programming and generaly as programming approach, that I wan't to suggest you at this moment. Anyhow, that splitting of response I used to do because I did not know for MTU, but had the same problem (sometimes response was correct, sometimes not, but that was depending of the data transported over network). My suggestion is that it is worth to spent time to find out the problem.
Regards Peter !- Edited by Petar Nedic Monday, June 22, 2009 7:50 AM
-
Thursday, June 25, 2009 4:20 PM
You're The Best
Its working : - )
many thanks for your incredible help & attention.
Now i have another question, do you know any way to block the msn, internet explorer, all the programs that access to the internet expect my application.All the users have a “htc touch 3g”
Thanks for everything J
Cheers
Ricardo -
Tuesday, July 14, 2009 3:21 PMHi,
i have the same problem! Can you tell me how do you solve it? Please, its very urgent, i have no idea how to fix it. -
Friday, July 24, 2009 7:33 AM
Excellent
I'm glad I helped you !
Ah, blocking explorer and msn... I do not have such problems due to "deal" with mobile provider. Our SIM cards are set just to work through the VPN tunnel and as I understand set to point only to the one IP address (our server). So our HH devices using SIM cards work just as part of internal company network. Really I don't know details. Also on both sides of tunnel there are two cisco routers (gues so), that executes all the job.
So, I do not know the configuration of your network, but think about this.
Also, there is one more option on "my" devices (PSION WorkaboutPRO), which I do not use. Psion provides two operational modes: "Supervisor" and "User" mode. I use supervisor mode which provide full access to everything on HH (due to some reasons). User mode is extremely restricted but good in way that you can define what user can do (everything else is forbidden). So, if you restrict use of internet explorer and msn (in other words allow to use ONLY your application), you will solve the problem. I suppose your application use calls to one specific IP addresss (just calling different webservices, or pages). This is the case on my app. I have created one application on IIS (which resides on server). So any call by HH is pointed to this one IP address. I know that lot of people do not like IIS due to security reasons, but till now I haven't had any security issue (I'll not say it twice :)).
Well in one word: blocking IE and MSN will not block your application to communicate with server.
Hope I gave you some new ideas.
Regards- Edited by Petar Nedic Friday, July 24, 2009 7:39 AM
-
Tuesday, August 31, 2010 11:51 AM
Thank you very much for taking the time to write this solution, I have finally managed to solve this problem using your advice,
thanks again,
Tim
-
Monday, September 06, 2010 6:50 AM
I am having the same problem.
I' m sending stream of 1000 bytes of data to linux server. it accepts first 1000 bytes & returns me WebException
Unable to read data from transport connection."
If i send same stream to windows server it accepts.
I didn't findout where the exception occured.
-
Wednesday, May 09, 2012 3:56 PM
Hi Peter and thanks for the explanation.
I am having same issue as you reported above but only when device/emulator is cradled; otherwise, it is working fine.
I wonder if you had similar observation.
Thanks,
-- d.

