none
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 192.168.2.174:805 RRS feed

  • Question

  • I am receiving the error trying to validate an address using the USPS API.  What's baffling is that in development the code works great but when publishing to IIS v7 the error is thrown.  From the server I have tried successfully accessing the URL for the API (http://production.shippingapis.com/ShippingAPITest.dll).  From the server I have opened all inbound ports in the Firewall for testing.  The IP:port referenced is not one I recognize.  It's not a valid IP on my network so I'm not sure where this address is coming from.

    ERROR THROWN:

    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 192.168.2.174:805

    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: System.Net.Sockets.SocketException: 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 192.168.2.174:805

    Source Error: Line 45: Line 46: //Send the request to USPS. Line 47: byte[] ResponseData = wsClient.DownloadData(USPS_Request); Line 48: Line 49: //Convert byte stream to string data.

    Stack Trace: [SocketException (0x274c): 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 192.168.2.174:805] System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress) +395 System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Exception& exception) +503


    namespace USPSLookup
    {
        public class WebTools
        {
            private const string BaseUrl = "http://production.shippingapis.com/ShippingAPITest.dll";
            private readonly WebClient wsClient = new WebClient();
            public string USPS_UserID = "myValidUserNamexxxxxx";
    
            public  WebTools()
            {
            }
    
            //Constructor with User ID parameter. 
            public  WebTools(string New_UserID)
            {
                USPS_UserID = New_UserID;
            }
    
            /******************************************************* 
            * Send request to remote site. Return reply data. 
            ******************************************************/
    
            private string GetDataFromSite(string USPS_Request)
            {
                string strResponse = "";
    
                //Send the request to USPS. 
                byte[] ResponseData = wsClient.DownloadData(USPS_Request);
    
                //Convert byte stream to string data. 
                foreach (byte oItem in ResponseData)
                    strResponse += (char)oItem;
                return strResponse;
            }
    		
    		public string AddressValidateRequest(string Address1,
                                                 string Address2,
                                                 string City,
                                                 string State,
                                                 string Zip5,
                                                 string Zip4)
            {
                string strResponse = "", strUSPS = "";
                strUSPS = BaseUrl + "?API=Verify&XML=<AddressValidateRequest USERID=\"" + USPS_UserID + "\">";
                strUSPS += "<Address ID=\"0\">";
                strUSPS += "<Address1>" + Address1 + "</Address1>";
                strUSPS += "<Address2>" + Address2 + "</Address2>";
                strUSPS += "<City>" + City + "</City>";
                strUSPS += "<State>" + State + "</State>";
                strUSPS += "<Zip5>" + Zip5 + "</Zip5>";
                strUSPS += "<Zip4>" + Zip4 + "</Zip4>";
                strUSPS += "</Address></AddressValidateRequest>";
                //Send the request to USPS. 
                strResponse = GetDataFromSite(strUSPS);
                return strResponse;
            }
    		
        }
    
    
    


    Tuesday, February 27, 2018 7:39 PM

All replies

  • What's baffling is that in development the code works great but when publishing to IIS v7 the error is thrown. 

    Do you mean it worked great  with IIS Express? But you never used Visual Studio to deploy the Web project to local IIS, the real IIS, and run, debug and test the code against local IIS -- the real IIS that's local on the development machine? Now, you deployed to IIS on a server the Web solution only to discover that it doesn't work.  

    Tuesday, February 27, 2018 10:22 PM
  • >> What's baffling is that in development the code works great but when publishing to IIS v7 the error is thrown

    In development mode, could you access this USPS from this client?

    >>From the server I have tried successfully accessing the URL for the API

    For this working scenario, did it work from Server while you publish to IIS or in development?

    To check whether it is related with environment configuration, I suggest you place a Html page in the published application, then try to access this page from your client. Could you access it?

    To check whether there is any issue while publishing, I suggest you turn to Project property->Web->Servers->Change IIS Express to IIS->Create Virtual Directory->Run project, and try to access the service.


    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.

    Wednesday, February 28, 2018 2:12 AM
  • Yes, in IIS Express installed on the local DEV machine (with Visual Studio), all is grand.
    Wednesday, February 28, 2018 10:08 PM
  • Yes, the URL for USPS API is accessible from both the client and the server.  

    During testing, prior to publishing the application works fine.  After publishing running the web-application directly from the server it chokes and fails with the error.   

    I'll try your suggestion, changing from IIS express to IIS.

    Wednesday, February 28, 2018 10:12 PM
  • If you have any update about your issue, please feel free to let us know.

    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.

    Thursday, March 1, 2018 1:31 AM
  • Yes, in IIS Express installed on the local DEV machine (with Visual Studio), all is grand.

    Well, what you should do is right-click the Web project in Visual Studio, go to Properties, go to the Web tab and change the server from IIS Express  to local IIS, the real IIS, and press the 'create virtual directory.

    By doing this, you deploy the Web project to local IIS, the real IIS, and it hooks the project source code up to local IIS too so that you can debug the project using the VS's debugger to debug the code and catch exceptions through Visual Studio. 

    You must start Visual Studio using "Run as Administrator" in order to do what I am  talking about. It is mandatory that you do this and run the solution against local IIS before trying to do a deployment to IIS to avoid any surprises.

    I have never used IIS Express in my home development environment nor have I seen IIS Express being used in any professional work environment either, because one knows that things will work  on IIS Express, but that doesn't mean that it is going to work on IIS, the real one.

    Thursday, March 1, 2018 5:00 AM
  • I know it is almost two years old post, however, I am facing this exact issue on localhost but not in QA+ environment.

    Any idea?

    Friday, February 14, 2020 3:40 PM