« Previous Next »

Thread: “Unable to connect to remote server fail” in HttpWebRequest

Last post 10-21-2009 11:44 PM by George2. 16 replies.

Average Rating Rate It (5)

RSS

Page 1 of 2 (17 items) 1 2 Next >

Sort Posts:

  • 10-21-2009, 12:53 AM

    • George2
    • Top 75 Contributor
    • Joined on 09-03-2008, 12:48 PM
    • Posts 106

    “Unable to connect to remote server fail” in HttpWebRequest

    Hello everyone,

    I am using VSTS 2008 + C# + .Net 3.5 to develop a console application and I send request to another server (IIS 7.0 on Windows Server 2008). I find when the # of request threads are big (e.g. 2000 threads), the client will receive error "Unable to connect to remote server fail" when invoking response = (HttpWebResponse)request.GetResponse().My confusion is -- I have set timeout to be a large value, but I got such fail message within a minute. I think even if the connection are really larger than what IIS could serve, client should not get such fail message so soon, it should get such message after timeout period. Any comments? Any ideas what is wrong? Any ideas to make more number of concurrent connection being served by IIS 7.0?

    Here is my code,

           class Program
            {
                private static int ClientCount = 2000;
                private static string TargetURL = "http://labtest/abc.wmv";
                private static int Timeout = 3600;
       
                static void PerformanceWorker()
                {
                    Stream dataStream = null;
                    HttpWebRequest request = null;
                    HttpWebResponse response = null;
                    StreamReader reader = null;
                    try
                    {
                        request = (HttpWebRequest)WebRequest.Create(TargetURL);
                        request.Timeout = Timeout * 1000;
                        request.Proxy = null;
                        response = (HttpWebResponse)request.GetResponse();
                        dataStream = response.GetResponseStream();
                        reader = new StreamReader(dataStream);
       
                        // 1 M at one time
                        char[] c = new char[1000 * 10];
       
                        while (reader.Read(c, 0, c.Length) > 0)
                        {
                            Console.WriteLine(Thread.CurrentThread.ManagedThreadId);
                        }
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message + "\n" + ex.StackTrace);
                    }
                    finally
                    {
                        if (null != reader)
                        {
                            reader.Close();
                        }
                        if (null != dataStream)
                        {
                            dataStream.Close();
                        }
                        if (null != response)
                        {
                            response.Close();
                        }
                    }
                }
               
                static void Main(string[] args)
                {
                    Thread[] workers = new Thread[ClientCount];
                    for (int i = 0; i < ClientCount; i++)
                    {
                        workers[i] = new Thread((new ThreadStart(PerformanceWorker)));
                    }
       
                    for (int i = 0; i < ClientCount; i++)
                    {
                        workers[i].Start();
                    }
                  
                    for (int i = 0; i < ClientCount; i++)
                    {
                        workers[i].Join();
                    }          
       
                    return;
                }
            }

    thanks in advance,
    George

     

  • 10-21-2009, 1:20 AM In reply to

    • lextm
    • Top 10 Contributor
    • Joined on 10-22-2008, 4:18 AM
    • Shanghai, PRC
    • Posts 1,390

    Re: “Unable to connect to remote server fail” in HttpWebRequest

    You'd better check both IIS logs and HTTP error logs on the IIS server. Generally speaking, HTTP.sys component will stop accepting new connections when it cannot afford them. That will trigger a client side error immediately instead of timeout sometimes.
    Lex Li
    Support Engineer at Microsoft
    ---------------------------
    This posting is provided "AS IS" with no warranties, and confers no rights.
  • 10-21-2009, 2:26 AM In reply to

    • George2
    • Top 75 Contributor
    • Joined on 09-03-2008, 12:48 PM
    • Posts 106

    Re: “Unable to connect to remote server fail” in HttpWebRequest

    For "IIS logs and HTTP error logs", could you specify in more details which files do you mean?

  • 10-21-2009, 2:35 AM In reply to

    • lextm
    • Top 10 Contributor
    • Joined on 10-22-2008, 4:18 AM
    • Shanghai, PRC
    • Posts 1,390

    Re: “Unable to connect to remote server fail” in HttpWebRequest

    IIS logs contain web site access records,

    http://support.microsoft.com/kb/943891

    while HTTP error logs contain HTTP.sys activities,

    http://support.microsoft.com/kb/820729

    Lex Li
    Support Engineer at Microsoft
    ---------------------------
    This posting is provided "AS IS" with no warranties, and confers no rights.
  • 10-21-2009, 2:42 AM In reply to

    • George2
    • Top 75 Contributor
    • Joined on 09-03-2008, 12:48 PM
    • Posts 106

    Re: “Unable to connect to remote server fail” in HttpWebRequest

    I am a little bit confused, IIS log and Http log, they are different things? What are the differences and purposes between them?

  • 10-21-2009, 2:47 AM In reply to

    • lextm
    • Top 10 Contributor
    • Joined on 10-22-2008, 4:18 AM
    • Shanghai, PRC
    • Posts 1,390

    Re: “Unable to connect to remote server fail” in HttpWebRequest

    That's a long history to tell. In short, IIS logs are closely related to IIS web site parts, while HTTP error logs are closely related to a Windows driver named http.sys. They are different things.
    Lex Li
    Support Engineer at Microsoft
    ---------------------------
    This posting is provided "AS IS" with no warranties, and confers no rights.
  • 10-21-2009, 2:56 AM In reply to

    • George2
    • Top 75 Contributor
    • Joined on 09-03-2008, 12:48 PM
    • Posts 106

    Re: “Unable to connect to remote server fail” in HttpWebRequest

    I am confused. I am testing against IIS, do you mean IIS log itself is not enough and we have to use additional http.sys log? My confusion is why IIS log itself is not enough for testing on IIS application (as in my scenario).

  • 10-21-2009, 3:03 AM In reply to

    • lextm
    • Top 10 Contributor
    • Joined on 10-22-2008, 4:18 AM
    • Shanghai, PRC
    • Posts 1,390

    Re: “Unable to connect to remote server fail” in HttpWebRequest

    Please understand IIS is not a single process program but a Windows system component that is composed of many pieces.

    It will be irrational to put all logging information into one place as difference sources have different things/structures to log.

    Yes, IIS log files mentioned in KB 943891 are not enough for diagnostics, as many relevant information can be logged in HTTP error logs, Application event log, System event log and many others.

    Regards,

    Lex Li
    Support Engineer at Microsoft
    ---------------------------
    This posting is provided "AS IS" with no warranties, and confers no rights.
  • 10-21-2009, 3:25 AM In reply to

    • George2
    • Top 75 Contributor
    • Joined on 09-03-2008, 12:48 PM
    • Posts 106

    Re: “Unable to connect to remote server fail” in HttpWebRequest

    Thanks! I followed directions in http://support.microsoft.com/kb/820729, and then I find in my registry, HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\HTTP\Parameters, there is no keys like EnableErrorLogging/ErrorLogFileTruncateSize/ErrorLoggingDir, but in directory C:\Windows\System32\LogFiles\HTTPERR under IIS 7.0 machine, there is already log files like httperr12.log. Does it mean by default Http.sys error will be logged and in my system, I do not need to configure any additional settings, and the Http.sys already works?

  • 10-21-2009, 3:28 AM In reply to

    • George2
    • Top 75 Contributor
    • Joined on 09-03-2008, 12:48 PM
    • Posts 106

    Re: “Unable to connect to remote server fail” in HttpWebRequest

    From logs under C:\Windows\System32\LogFiles\HTTPERR, I got failed reasons of two categories, any ideas what is wrong?


    HTTP/1.1 GET /test.wmv - 1 Timer_MinBytesPerSecond DefaultAppPool

    HTTP/1.1 GET /test.wmv - 1 Connection_Dropped_List_Full DefaultAppPool

  • 10-21-2009, 3:56 AM In reply to

    • lextm
    • Top 10 Contributor
    • Joined on 10-22-2008, 4:18 AM
    • Shanghai, PRC
    • Posts 1,390

    Re: “Unable to connect to remote server fail” in HttpWebRequest

    :) I hope you go through http://support.microsoft.com/kb/820729 and the answers are already there.

     

    Lex Li
    Support Engineer at Microsoft
    ---------------------------
    This posting is provided "AS IS" with no warranties, and confers no rights.
  • 10-21-2009, 5:40 AM In reply to

    • George2
    • Top 75 Contributor
    • Joined on 09-03-2008, 12:48 PM
    • Posts 106

    Re: “Unable to connect to remote server fail” in HttpWebRequest

    How to edit meta database of IIS 7.0 on Windows Server 2008? I read some tutorials and they said I should enable meta data editing feature from Properties of a web server in IIS management console. But when I right click on a web server in IIS management console, there is no menu called Properties.

    Here is what I am referring to. Any ideas what is wrong?

    http://www.microsoft.com/technet/prodtechnol/WindowsServer2003/Library/IIS/1d1e5de4-fd63-40cd-bc5d-c20521548eed.mspx?mfr=true

  • 10-21-2009, 5:57 AM In reply to

    • lextm
    • Top 10 Contributor
    • Joined on 10-22-2008, 4:18 AM
    • Shanghai, PRC
    • Posts 1,390

    Re: “Unable to connect to remote server fail” in HttpWebRequest

    Please search on IIS.net as most IIS 7 information is published here, http://learn.iis.net/. IIS 6 and IIS 7 have different configuration system so many IIS 6 articles like the one you found does not apply to IIS 7.
    Lex Li
    Support Engineer at Microsoft
    ---------------------------
    This posting is provided "AS IS" with no warranties, and confers no rights.
  • 10-21-2009, 6:09 AM In reply to

    • George2
    • Top 75 Contributor
    • Joined on 09-03-2008, 12:48 PM
    • Posts 106

    Re: “Unable to connect to remote server fail” in HttpWebRequest

    All I found is about meta compatibility of IIS 6 and IIS 7. Could you refer me a document from iis.net about how to edit meta database please? :-)

  • 10-21-2009, 6:14 AM In reply to

    • lextm
    • Top 10 Contributor
    • Joined on 10-22-2008, 4:18 AM
    • Shanghai, PRC
    • Posts 1,390

    Re: “Unable to connect to remote server fail” in HttpWebRequest

    IIS 7 does not have that. To edit IIS 7 settings, you can utilize IIS Manager, or edit %windir%\system32\inetsrv\config\applicationHost.config directly.

    Lex Li
    Support Engineer at Microsoft
    ---------------------------
    This posting is provided "AS IS" with no warranties, and confers no rights.
Page 1 of 2 (17 items) 1 2 Next >
Microsoft Communities