locked
[Win8.1]StreamSocket cannot suppot WPAD(Web_Proxy_Autodiscovery_Protocol)?

    Question

  • I have got a proxy connection problem, list 2 proxy types with different connected APIs below:

    1. Connecting to standard proxy server, setup proxy server/port in IE, import via netsh and pass credential in IE

    1.a System.Net.Http.HttpClient (connected, works fine)

    handler = new System.Net.Http.HttpClientHandler();
    handler.Proxy = WebRequest.DefaultWebProxy; 
    handler.Proxy.Credentials = CredentialCache.DefaultCredentials;
    client = new System.Net.Http.HttpClient(handler);

    1.b Windows.Web.Http.HttpClient (connected, works fine)

    client = new Windows.Web.Http.HttpClient();

    1.c StreamSocket (connected, works fine)

    System.Uri uri = new Uri("http://www.microsoft.com"); ProxyConfiguration pc = await NetworkInformation.GetProxyConfigurationAsync(uri); // pc.CanConnectDirectly = false

    StreamSocket client = new StreamSocket();


    2. Connecting to WPAD proxy server, no setting required, pass the credential in IE, connected to internet (http://en.wikipedia.org/wiki/Web_Proxy_Autodiscovery_Protocol)

    2.a System.Net.Http.HttpClient (connected, need to create the credential manually)

    handler = new System.Net.Http.HttpClientHandler();
    handler.Proxy = WebRequest.DefaultWebProxy; 
    handler.Proxy.Credentials = new NetworkCredential("username", "password");
    client = new System.Net.Http.HttpClient(handler);

    2.b Windows.Web.Http.HttpClient (connected, works perfect)

    client = new Windows.Web.Http.HttpClient(); 

    2.c StreamSocket (cannot connect, 407 Proxy authentication required)

    System.Uri uri = new Uri("http://www.microsoft.com");
    ProxyConfiguration pc = await NetworkInformation.GetProxyConfigurationAsync(uri);
    // pc.CanConnectDirectly = true <---- cannot detect the proxy server
    
    StreamSocket client = new StreamSocket();

    ===

    My question is that with the case 2.c, the CanConnectDirectly is true means StreamSocket cannot detect proxy to connect.

    Is this a bug? or do i miss any settings?

    ===

    PS: case 2, cannot detect proxy via netsh, too

    netsh winhttp import proxy source=ie

    Current WinHTTP proxy settings:
        Direct access (no proxy server).

    Best Regards.



    • Edited by BinBin Tsai Friday, August 29, 2014 3:50 AM add WPAD
    Friday, August 29, 2014 3:01 AM

Answers

  • I think I found the problem.

    StreamSocket works fine (pc.CanConnectDirectly=false) after changed the proxy.pac from

    function FindProxyForURL(url, host)
        {
           return "PROXY proxy.xxx.com:3128; DIRECT";
        }

    to

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

    Can Microsoft fix this issue? or Do I need to add any setting for StreamSocket?  

    • Marked as answer by BinBin Tsai Friday, September 5, 2014 7:42 AM
    Friday, August 29, 2014 10:08 AM

All replies

  • I think I found the problem.

    StreamSocket works fine (pc.CanConnectDirectly=false) after changed the proxy.pac from

    function FindProxyForURL(url, host)
        {
           return "PROXY proxy.xxx.com:3128; DIRECT";
        }

    to

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

    Can Microsoft fix this issue? or Do I need to add any setting for StreamSocket?  

    • Marked as answer by BinBin Tsai Friday, September 5, 2014 7:42 AM
    Friday, August 29, 2014 10:08 AM
  • Hi BinBin Tsai,

    Thanks for your feedback, so the question now is you want to know if you do not modify the proxy.pac file, how to make StreamSocket support WPAD.

    ProxyConfiguration.CanConnectDirectly | canConnectDirectly property is a read-only value, we cannot set anything for it.

    As I know the WPAD script used to supply proxy information to a web browser or HttpClient tells Windows that it should use the proxy. This can cause problems when the remote endpoint is not expecting a proxy connection (an HTTP CONNECT request, for example). An app can use the  GetProxyConfigurationAsync method on the NetworkInformation object passing the remote endpoint and port for the uri parameter to retrieve proxy information to help determine when this condition is suspected.A way to avoid proxy connection requests from being sent when a server can only handle direct connections is to use the ConnectAsync(HostName, String, SocketProtectionLevel, NetworkAdapter) method, since the proxy-related logic is disabled when a specific network adapter is selected.

    --James

    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Friday, August 29, 2014 10:44 AM
    Moderator
  • Thanks, James.

    I had passed the current uri to GetProxyConfiguration and got CanConnectDirectly = true.

    But I got 407 when called ConnectAsync (w/o NetworkAdapter), it's really strange.

    GetProxyConfiguration should return me false when the uri cannot connect directly.

     There is no problem with Windows.Web.Http.HttpClient.

    I will try to fig out what the problem is.

    Best Regards.

    Monday, September 1, 2014 2:51 AM