Question

I have created a C sharp Wpf ClickOnce application which uses xml rpc for communincation. A lot of my users get there proxy settings in different ways. Some use a pac file, other from IE or dhcp etc. I want to automate this whole process of getting the proxy details in any kind of environment. I have tried a LOT of different code snippets but want to hear if something like this already exists.

I see the Xml Rpc documentation has a setProxy method but I'm not sure how to specify the username or passsword if one is used. This whole process is still a little bit confusing for me.

I have also tried many different pieces of code including the WebProxy Class and using DefaultCredentials,DefaultProxy,GetSystemWebProxy etc.

At the moment I'm going to try a dllimport using winhttp to get the proxy settings. I am not sure if one can do this in a Clickonce Deployment. Is the dllimport the same as p/invoke ?

As you can see I would appreciate some advice on how to go about getting ANY type of proxy setting.

Appreciate any feedback.

Was it helpful?

Solution 2

This worked for me :

public static IExample ProxyAndCredentials { get; set; }
public static string ProxyUrl { get; set; }

public static void SetupProxyAndCredentials() {

  //Insert your website here where XmlRpc calls should go
  var url = new Uri("http://www.example.com/");   

  try
  {
    ProxyUrl = WebRequest.DefaultWebProxy.GetProxy(url).ToString();
    Log.Debug(url + "    is using proxy      " + ProxyUrl);

    if (ProxyUrl == url.ToString() || ProxyUrl == url + "/"){

    // A proxy is not in use here
    ProxyUrl = "";
    Log.Debug("No proxy is used for " + url);

    }
    else if (!String.IsNullOrEmpty(ProxyUrl)){

    // A proxy is in use
    ProxyAndCredentials.Proxy = new WebProxy(ProxyUrl);
    Log.Debug("A proxy is used for " + url);

    }

    //Set credentials, in my experience it is better to always set these
    ProxyAndCredentials.Credentials = CredentialCache.DefaultNetworkCredentials;
    ProxyAndCredentials.Proxy.Credentials = CredentialCache.DefaultNetworkCredentials;
  }
  catch (Exception p)
  {
    //Handle Exception
  }
}

OTHER TIPS

ClickOnce installation/update doesn't really support proxy authentication. It will use the information in IE, and sometimes the machine.config file. The definitive thread with all known information about this is here.

I haven't had have problems with proxy authentication from the standpoint of installing applications. When using our application, which called backend WCF services, we let the user provide his proxy authentication information, and we applied the settings programmatically when making the service calls. This has nothing to do with ClickOnce.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top