System.Net.WebRequest - timeout error

The following code snippet gives the error message: "Operation completed" Sourse error: at System.Net.httpWebRequest.GetResponse ()

This method calls the URL and receives the response object.

NOTE. All this works fine at my end ... but when I send the same code to production .. it shows the time of no errors

public GetUpdatedInventoryUnitValues(Vehicle aeVehicle)
{
            WebRequest oWebRequest = null;
            StringBuilder oStringBuilder = null;
            StreamReader oStreamReader = null;
            dcDealerDetails = new Dictionary<string, string>();

            MSRP = string.Empty;
            NetPrice = string.Empty;
            string strLine = string.Empty;
            string strURL = GetUpdatedInventoryUnitValues.GetFormattedURL(aeVehicle);

            try
            {
                /* Open the requested URL */
                oWebRequest = WebRequest.Create(strURL);
                oWebRequest.Method = "GET";
                oWebRequest.ContentType = "application/xml";
                /* Get the stream from the returned web response */
                oStreamReader = new StreamReader(oWebRequest.GetResponse().GetResponseStream());
                /* Get the stream from the returned web response */
                oStringBuilder = new StringBuilder();
                /* Read the stream a line at a time and place each one into the stringbuilder  */
                while ((strLine = oStreamReader.ReadLine()) != null)
                {
                    /* Ignore blank lines */
                    if (strLine.Length > 0)
                        oStringBuilder.Append(strLine);
                }

                string[] tempArray = null;
                string[] tempNextArray = null;
                //Split string by semicolon as a separater
                tempArray = Data.SplitString(oStringBuilder.ToString(), new char[] { ';' });

                if (tempArray != null)
                {
                    foreach (string invUnits in tempArray)
                    {
                        //Split string by '=' as a separater
                        tempNextArray = Data.SplitString(invUnits, new char[] { '=' });

                        if (tempNextArray != null && tempNextArray.Length == 2)
                        {
                            switch (tempNextArray[0].ToLower())
                            {
                                //case "msrp":
                                //    MSRP = Data.RemoveDoubleCode(tempNextArray[1]);
                                //    break;
                                case "netprice":
                                    NetPrice = Data.RemoveDoubleCode(tempNextArray[1]);
                                    break;
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                ErrorLog.ErrorMessage = ErrorLog.Separator;
                ErrorLog.ErrorMessage = "Exception during posting data to another application .";
                ErrorLog.ErrorMessage = "ERROR MESSAGE : " + ex.Message;
                ErrorLog.ErrorMessage = "ERROR SOURCE: " + ex.StackTrace.ToString();

            }
            finally
            {
                if (oStreamReader != null)
                {
                    oStreamReader.Close();
                }
                if (oWebRequest != null)
                {
                    oWebRequest = null;
                }
            }
        }

Please suggest what am I doing wrong or not enough?

+5
source share
3 answers

Perhaps you find that the first few queries are in order, and then they start the countdown? If so, I suspect this is a problem:

oStreamReader = new StreamReader(oWebRequest.GetResponse().GetResponseStream());

You get an answer, but don't get rid of it. You should use:

using (var response = oWebRequest.GetResponse())
{
    ...
}

, finally, using.

, - 77 ! - , :

  • , , .
+17

.

"Operation Timed Out".

WebClient And WebRequest ( Timeout), .

, .

, , :

using (var response = oWebRequest.GetResponse())

{
    ...
}

...

+2

, :

    WebRequest webRequest = WebRequest.Create(requestUri);
    webRequest.Credentials = new NetworkCredential(login, password);
    WebResponse webResponse = webRequest.GetResponse();
    Stream response = webResponse.GetResponseStream();
    StreamReader reader = new StreamReader(response);

, , , .

+1

All Articles