Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Calling Web Service

Calling Web Service

Scheduled Pinned Locked Moved C#
csharpsysadminhelpquestion
4 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    DinoRondelly
    wrote on last edited by
    #1

    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?

    A T K 3 Replies Last reply
    0
    • D DinoRondelly

      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?

      A Offline
      A Offline
      Abhinav S
      wrote on last edited by
      #2

      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.

      1 Reply Last reply
      0
      • D DinoRondelly

        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?

        T Offline
        T Offline
        Tony Richards
        wrote on last edited by
        #3

        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?

        1 Reply Last reply
        0
        • D DinoRondelly

          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?

          K Offline
          K Offline
          Keith Barrow
          wrote on last edited by
          #4

          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, that catch block is a bad idea, generally it is bad to catch the base Exception 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.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups