tags:

views:

1071

answers:

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.

A: 

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

RandomNoob
You'll need GetDefaultProxy().Address
RandomNoob
+1  A: 

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