locked
The underlying connection was closed - Very Annoying RRS feed

  • Question

  • User579345625 posted

    Hi,

     

    I am facing this very annoying problem since 2-3 days. Following code is working fine on other machines, infact it used to work perfectly fime on my machine also few days back. But now its not. I am totally lost. Please help.<o:p></o:p>

    <o:p> </o:p>

    <o:p> </o:p>

    Following statement is throwing an Exception: <o:p></o:p>

    <o:p> </o:p>

    WebResponse response = webRequest.GetResponse();<o:p></o:p>

    <o:p> </o:p>

    <o:p> </o:p>

    And the Exception is:<o:p></o:p>

    <o:p> </o:p>

    System.Net.WebException - The underlying connection was closed: An unexpected error occurred on a receive.<o:p></o:p>

    <o:p> </o:p>

    <o:p> </o:p>

    Following is the complete code of the function:<o:p></o:p>

    <o:p> </o:p>

    public static Stream GetResponseStream(string url, XmlDocument searchRequestXML)<o:p></o:p>

            {<o:p></o:p>

                Stream responseStream = null;<o:p></o:p>

                try<o:p></o:p>

                {<o:p></o:p>

                   <o:p></o:p>

     HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(url);<o:p></o:p>

                    NetworkCredential nc = new NetworkCredential("tyrelink","tyrelink");<o:p></o:p>

                    webRequest.Credentials = nc;<o:p></o:p>

                    webRequest.KeepAlive = false;<o:p></o:p>

                    webRequest.Headers.Add("SOAPAction", "\"\"");<o:p></o:p>

                    webRequest.ContentType = "text/xml;charset=\"utf-8\"";<o:p></o:p>

                    webRequest.Accept = "text/xml";<o:p></o:p>

                    webRequest.Method = "POST";<o:p></o:p>

                    Stream webRequestStream = webRequest.GetRequestStream();<o:p></o:p>

                    searchRequestXML.Save(webRequestStream);<o:p></o:p>

                    webRequestStream.Close();<o:p></o:p>

    <o:p> </o:p>

                    WebResponse response = webRequest.GetResponse();<o:p></o:p>

                    responseStream = response.GetResponseStream();<o:p></o:p>

    <o:p> </o:p>

                }<o:p></o:p>

                catch (Exception ex)<o:p></o:p>

                {<o:p></o:p>

    throw new tyreLinkDBException ("GETTING_THE_RESPONSE_FAILED", null, ex);<o:p></o:p>

                }<o:p></o:p>

                finally<o:p></o:p>

                {<o:p></o:p>

                 <o:p></o:p>

                }<o:p></o:p>

                return responseStream;<o:p></o:p>

            }<o:p></o:p>

     

     

    Please get me out of this, I am going creazy !!!

     Thanks,

    Anup
     

    Sunday, June 17, 2007 10:32 AM

Answers

  • User579345625 posted

     Got the problem:

     I uninstalled the Safari Browser for windows, which unexpectedly cleared the proxy settings in my IE. (Properties >> Connections >> LAN Settings >> Advanced >> Bypass Proxies)

     And one more quote:

     Safari for Windows is not at all worth installing, I was facing frequent crashes and it makes you close many applications rigth from Firefox to VS2005.

     My Advice: Dont go for it.

     

    Thanks,

    Anup
     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, June 27, 2007 11:51 PM

All replies

  • User-2005691517 posted

    Setting the useragent property of the webrequest object normally solves this problem, e.g.

    webRequest.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.8.0.5) Gecko/20060719 Firefox/1.5.0.5)"

    or

    webRequest.UserAgent = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 2.0.50727; .NET CLR 1.1.4322; .NET CLR 1.0.3705; .NET CLR 3.0.04506.30; MEGAUPLOAD 1.0)" 

    These are the values from Firefox and IE. You could very well use your own e.g. "My User Agent" 

    Sunday, June 17, 2007 10:54 AM
  • User579345625 posted

     Hi Peashant,

    " webRequest.UserAgent" didnt help :(

    problem still exists!

     

    Few things which might be related to the case :

    1. My OS is Windows XP SP2

    2. Its a Web Application and not a Web Service

    3. I had installed the Safari browser for windows and then uninstalled it. While uninstalling, it made me closing the Firefox, VS2005 and few other running application?

     

     

    Waiting for the responses ,

     Thanks,

    Anup
     

     

    Sunday, June 17, 2007 11:55 AM
  • User-225114762 posted

    Have you checked if your credentials that you provide to the remote server are still valid?

    Monday, June 18, 2007 5:17 AM
  • User579345625 posted

     Got the problem:

     I uninstalled the Safari Browser for windows, which unexpectedly cleared the proxy settings in my IE. (Properties >> Connections >> LAN Settings >> Advanced >> Bypass Proxies)

     And one more quote:

     Safari for Windows is not at all worth installing, I was facing frequent crashes and it makes you close many applications rigth from Firefox to VS2005.

     My Advice: Dont go for it.

     

    Thanks,

    Anup
     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, June 27, 2007 11:51 PM