Question

When trying to invoke a method on an external webservice (over the Internet) it throws me "The remote server returned an error: (407) Proxy Authentication Required."

To solve this, I used the following code to set the proxy we use in the office:

//Set the system proxy with valid server address or IP and port.
System.Net.WebProxy pry = new System.Net.WebProxy("MyHost", 8080);

//The DefaultCredentials automically get username and password.
pry.Credentials = System.Net.CredentialCache.DefaultCredentials;
System.Net.WebRequest.DefaultWebProxy = pry;

That works fine, but now... I need to do that "less harcoded" trying to get the information from my system instead of setting that manually.

Was it helpful?

Solution

This will use whatever the default proxy is for IE I believe (not deprecated):

Services.MyService service = new Services.MyService();
service.UseDefaultCredentials = true;
service.Proxy = new System.Net.WebProxy();
service.Proxy.Credentials = service.Credentials;

OTHER TIPS

System.Net.WebProxy.GetDefaultProxy() although VS cautions its been deprecated.

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