locked
DNS resolution failure in HttpClient when using Automatic Configuration Scripts

    Question

  • I have a WinRT(C# .NET for Windows Store apps .NETCore,Version=v4.5) client app using HttpClient. When I use automatic configuration scripts and disconnect my computer from a network, call WebRequest.DefaultWebProxy.GetProxy, connect to a network, call HttpClient.SendAsync then an HttpRequestException gets thrown.

     1. Use Automatic Configuration Scripts (Web Proxy Configuration)
     2. Network OFF
     3. Call WebRequest.DefaultWebProxy.GetProxy
     4. Network ON
     5. Call HttpClient.SendAsync()
     6. HttpRequestException (DNS Resolution Failure)
     

    Is this a known bug or restrictions?

    [similar restrictions] http://support.microsoft.com/kb/2863422/ja  (Japanese Only)
    • Edited by k_kato2501 Monday, June 23, 2014 4:54 AM
    Monday, June 23, 2014 4:49 AM

All replies

  • I don't understand the point of this exercise. You call GetProxy when there's no network, then wonder why the send fails when the network is back? It sounds like you just don't have good information about the proxy. How about prevent this from occurring in the first place?

    If I am missing something, please explain it to me.


    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Monday, June 23, 2014 7:59 PM
    Moderator
  • 1) Use Automatic Configuration Scripts (Web Proxy Configuration). 

     http://extranet.com/proxy.pac (not intranet)

    [proxy.pac]

    function FindProxyForURL(url, host)
    {
    	return "PROXY your.proxy.com:8080; PROXY your.proxy.com:8080";
    }

    [Visual Studio 2012 Express for Windows 8 > UnitTestLibrary]

    using Microsoft.VisualStudio.TestPlatform.UnitTestFramework;
    using System;
    using System.Diagnostics;
    using System.Net;
    using System.Net.Http;
    using System.Net.NetworkInformation;
    using System.Threading.Tasks;
    
    namespace HttpClientTest
    {
        [TestClass]
        public class HttpClientTest
        {
            [TestMethod, TestCategory("Abnormal")]
            public async Task HttpClient_DNS_Fail()
            {
                // arrange
                // You should use external PAC Automatic Configuration Scripts
                while (NetworkInterface.GetIsNetworkAvailable())
                {
                    Debug.WriteLine("Network is Available... Please disconnect your computer from a network.");
                    await Task.Delay(TimeSpan.FromSeconds(5));
                }
    
                // act
                Uri dst = new Uri("http://social.msdn.microsoft.com/");
                Uri proxyGetFromAutomaticConfigurationScripts = WebRequest.DefaultWebProxy.GetProxy(dst);
    
                while (!NetworkInterface.GetIsNetworkAvailable())
                {
                    Debug.WriteLine("Network is Disavailable... Please connect your computer to a network.");
                    await Task.Delay(TimeSpan.FromSeconds(5));
                }
    
                try
                {
                    HttpResponseMessage response = await new HttpClient().GetAsync(dst);
                    // assert normal
                    Assert.AreEqual(200, (int)response.StatusCode);
                }
                catch (HttpRequestException e)
                {
                    WebException webex = (WebException)e.InnerException;
                    // assert abnormal
                    Assert.AreNotEqual("The remote name could not be resolved: 'social.msdn.microsoft.com'", webex.Message);
                    Assert.AreNotEqual(-2146233079, webex.HResult);
                }
            }
        }
    }


    • Edited by k_kato2501 Tuesday, June 24, 2014 3:02 AM
    Tuesday, June 24, 2014 3:00 AM
  • You still haven't explained what the purpose here is.

    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Thursday, June 26, 2014 6:29 PM
    Moderator