none
System.Net.Sockets.SocketException (0x80004005): A connection attempt failed because the connected party did not properly respond after a period of time RRS feed

  • Question

  • Hi,

    I have been battling this for weeks. I want to read xml string from an rss feed. It works fine on localhost and postman, but after i publish and deploy using FTP to the server, i get this error.

    Unable to connect to the remote server at System.Net.HttpWebRequest.GetResponse() at dayrunnerapp.Controllers.HomeController.callRss(String url) System.Net.Sockets.SocketException (0x80004005): A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond 52.1.31.92:80 at System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress) at System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Exception& exception)


    This is the function that reads the feed

     [WebMethod, AllowCrossSiteJson]
            private string callRss(string url)
            {
                string html = String.Empty;
                try
                {
                    HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
                    request.AutomaticDecompression = DecompressionMethods.GZip;
                    request.UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:6.0.2) Gecko/20100101 Firefox/6.0.2";
                    request.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
                    request.Headers.Add("Accept-Language", "en-gb,en;q=0.5");
                    request.Headers.Add("Accept-Charset", "ISO-8859-1,utf-8;q=0.7,*;q=0.7");
                    WebRequest.DefaultWebProxy.Credentials = CredentialCache.DefaultNetworkCredentials;
                    using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
                    using (Stream stream = response.GetResponseStream())
                    using (StreamReader reader = new StreamReader(stream))
                    {
                        html = reader.ReadToEnd();
                    }
                }
                catch (Exception ex)
                {
                    html = ex.Message+"\n"+ex.StackTrace + "\n" + ex.InnerException + "\n" + ex.InnerException.InnerException;
                }
    
                return html;
            }

    this is the feed url 

    var url = "http://www.inboundlogistics.com/cms/rss-feed";

    here is part of my web.config file

    <system.net>
        <defaultProxy useDefaultCredentials="true" />
    </system.net>

    Please what am i missing?


    Easy

    Monday, October 29, 2018 10:39 PM

All replies

  • Hi,

    Can you try adding below one line code after HttpWebRequest and check

    System.Net.ServicePointManager.SecurityProtocol |= SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;



    Cheers,

    Tuesday, October 30, 2018 1:48 AM
  • After adding the line, i still get exactly the same error after i publish to the web server, but its fine in localhost

    Easy

    Tuesday, October 30, 2018 2:23 AM
  • Hi EasyHero,

    According to your description, your issue is related about web service, so I suggest you can ask your question at Web Service forum for professional help.

    https://forums.asp.net/28.aspx

    Thank you for participating in the forum activities.

    Best Regards,

    Cherry


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, October 30, 2018 6:25 AM
  • A SocketException is thrown by the Socket and Dns classes when an error occurs with the network. Most of the time these are connectivity issues due to different IP protocols (IPV4/IPV6) between the two server/computers trying to communicate or extra authentication rules setup on one of the computers for in/out connectivity.  Ways to troubleshoot this SocketException are, check you have proper internet connection is there on your machine or not, and you are able to ping the remote server or not. Possible causes for the error:

    You are using the wrong IP address.
    You are using the wrong port.
    Firewall blocking the connection.


    Wednesday, June 3, 2020 6:00 AM