Calling Web Service
-
I am trying to call a web service multiple times inside a loop and it works fine locally on my computer but when i build it out to a server i get the following error. System.Net.WebException: The underlying connection was closed: An unexpected error occurred on a receive. ---> System.IO.IOException: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host I then added a try catch block as below
while (true) { tries++; try { myFile = myWebService.GenerateReportFile(clientID, drSchedule\["password"\].ToString(), Report, drSchedule\["APPLICAT"\].ToString(), ""); break; } catch (Exception we) { if(we.ToString().Contains("Reporter.MaxTrackException: No data found with current parameters.")) { nodata = true; break; } Console.WriteLine(DateTime.Now.ToString() + " " + AppName + ": " + we.ToString()); if(DateTime.Now > wstime.AddSeconds(60)) throw new Exception("After " + tries.ToString() + " tries:", we); System.Threading.Thread.Sleep(1500); } }
and i get the same error does anyone have any ideas as to what may be causing this?
-
I am trying to call a web service multiple times inside a loop and it works fine locally on my computer but when i build it out to a server i get the following error. System.Net.WebException: The underlying connection was closed: An unexpected error occurred on a receive. ---> System.IO.IOException: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host I then added a try catch block as below
while (true) { tries++; try { myFile = myWebService.GenerateReportFile(clientID, drSchedule\["password"\].ToString(), Report, drSchedule\["APPLICAT"\].ToString(), ""); break; } catch (Exception we) { if(we.ToString().Contains("Reporter.MaxTrackException: No data found with current parameters.")) { nodata = true; break; } Console.WriteLine(DateTime.Now.ToString() + " " + AppName + ": " + we.ToString()); if(DateTime.Now > wstime.AddSeconds(60)) throw new Exception("After " + tries.ToString() + " tries:", we); System.Threading.Thread.Sleep(1500); } }
and i get the same error does anyone have any ideas as to what may be causing this?
DinoRondelly wrote:
I am trying to call a web service multiple times inside a loop and it works fine locally
First of all, that is not a good idea. Web services should never be called in a loop. For your problem, the server might only allow a certain number of connections to it.
-
I am trying to call a web service multiple times inside a loop and it works fine locally on my computer but when i build it out to a server i get the following error. System.Net.WebException: The underlying connection was closed: An unexpected error occurred on a receive. ---> System.IO.IOException: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host I then added a try catch block as below
while (true) { tries++; try { myFile = myWebService.GenerateReportFile(clientID, drSchedule\["password"\].ToString(), Report, drSchedule\["APPLICAT"\].ToString(), ""); break; } catch (Exception we) { if(we.ToString().Contains("Reporter.MaxTrackException: No data found with current parameters.")) { nodata = true; break; } Console.WriteLine(DateTime.Now.ToString() + " " + AppName + ": " + we.ToString()); if(DateTime.Now > wstime.AddSeconds(60)) throw new Exception("After " + tries.ToString() + " tries:", we); System.Threading.Thread.Sleep(1500); } }
and i get the same error does anyone have any ideas as to what may be causing this?
The first thing I would check would be user permissions, firewalls and proxies. These are the things that tend to trip me up first. Do you have access to the internals of the webservice? Are you able to check what your program is sending to try ang get an idea of what's going silly?
-
I am trying to call a web service multiple times inside a loop and it works fine locally on my computer but when i build it out to a server i get the following error. System.Net.WebException: The underlying connection was closed: An unexpected error occurred on a receive. ---> System.IO.IOException: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host I then added a try catch block as below
while (true) { tries++; try { myFile = myWebService.GenerateReportFile(clientID, drSchedule\["password"\].ToString(), Report, drSchedule\["APPLICAT"\].ToString(), ""); break; } catch (Exception we) { if(we.ToString().Contains("Reporter.MaxTrackException: No data found with current parameters.")) { nodata = true; break; } Console.WriteLine(DateTime.Now.ToString() + " " + AppName + ": " + we.ToString()); if(DateTime.Now > wstime.AddSeconds(60)) throw new Exception("After " + tries.ToString() + " tries:", we); System.Threading.Thread.Sleep(1500); } }
and i get the same error does anyone have any ideas as to what may be causing this?
Fundamentally, the
myWebService
isn't having it's connection closed, and the server is timing it out. The server does this to prevent denial of service attacks. You need to closed the connection (just creating a new one and assigning it to code> just won't have the same effect. Additionally, thatcatch
block is a bad idea, generally it is bad to catch the baseException
type, and calling a service in a loop is bad practise.Dalek Dave: There are many words that some find offensive, Homosexuality, Alcoholism, Religion, Visual Basic, Manchester United, Butter. Pete o'Hanlon: If it wasn't insulting tools, I'd say you were dumber than a bag of spanners.