Web Service calls from behind proxy servers

Here's something I posted on Mar 4, 2005
 
Recently I implemented a crash reporting capability into a .Net application. When an unhandled exceptions occurs (or application ThreadException), the user is presented with a dialog prompting them to submit it as a crash report. The dialog in turn calls a web service on my web server to accept the crash data.

This worked just great, so long as the user had direct HTTP access to my web server. However, it didn't work so well when they were behind a proxy server. The specific problem was with a Squid proxy server with authentication requirements. In this case, the web service call resulted in the error: "System.Net.WebException: The request failed with HTTP status 407: Proxy Authentication Required."

It turned out that the solution was relatively straight-forward. The web service wrapper provided by Visual Studio creates a class inherited from SoapHttpClientProtocol. WebProxy.GetDefaultProxy will retrieve default IE proxy settings for use in web commands. You can then set the user's default credentials on the proxy instances using CredentialCache.DefaultCredentials. Here is some example code:

CrashWebServices webServices = new CrashWebServices ();

// Set the proxy settings to the default IE settings

webServices.Proxy = System.Net.WebProxy.GetDefaultProxy();

// In case proxy authentication is required,
ensure that we make the call with the user's current credentials

webServices.Proxy.Credentials = System.Net.CredentialCache.DefaultCredentials;

string message = webServices.SubmitCrash(email,
crashData);

Hope this helps!
Published Tue, Jun 14 2005 2:24 PM by Joshua Langemann

Comments

Monday, June 20, 2005 4:24 AM by Joshua Langemann

# re: Web Service calls from behind proxy servers

This would help if we would live in a perfect world with only microsoft software. You already takes it for granted that everybody had IE correctly configgured. If a user would use another browser this will fail.
My opion is that every applicaties should take care of it's own handling of (proxy) settings.

This is the same as only creating websites suited for IE and would crash on other browsers.
Tuesday, April 22, 2008 4:11 AM by wzyiec

# re: Web Service calls from behind proxy servers

Thank you very much

Leave a Comment

(required) 
(required) 
(optional)
(required) 
Please add 4 and 2 and type the answer here: