Get the URI from the default web proxy

I'm writing a program that should work without proxy and with proxy with authentication - automatically! It should call a WCF service. In this example the instance is called client. I also use a self written class (proxyHelper) that requests the credentials.

 BasicHttpBinding connection = client.Endpoint.Binding as BasicHttpBinding;<br/>
 connection.ProxyAddress = _???_<br/>
 connection.UseDefaultWebProxy = false;<br/>
 connection.BypassProxyOnLocal = false;<br/>
 connection.Security.Transport.ProxyCredentialType = HttpProxyCredentialType.Basic;<br/>
 client.ClientCredentials.UserName.UserName = proxyHelper.Username;
 client.ClientCredentials.UserName.Password = proxyHelper.Password;

I'm facing a problem getting the ProxyAddress. If I use HttpWebRequest.GetSystemWebProxy() to get actual defined proxy I see in debug mode the correct proxy address but it's a non public property. Setting UseDefaultWebProxy to true doesn't work and if I add the proxy address hard-coded and set the UseDefaultWebProxy to false it works fine. So... how can I gather the address of the default web proxy?

8
задан Raktim Biswas 20 August 2016 в 08:37
поделиться