2

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.

Romias
  • 13,783
  • 7
  • 56
  • 85

2 Answers2

1

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;
John
  • 17,163
  • 16
  • 65
  • 83
0

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

Ta01
  • 31,040
  • 13
  • 70
  • 99