I have a client application written in C# and I use a Web Reference to a SOAP webservice. Now this works fine on my development machine – and indeed it continued to work fine, up until I tested it from behind a proxy.

Many hours of searching MSDN and Google later I was a little the wiser (not much) about how to deal with proxy’s and authentication with .NET (I’m using v2 of the framework)

The first thing to check is whether .NET will auto detect the fact there is a proxy (from IE) or whether we have to set this manually. This depends on the <defaultProxy> element in the .config file. Check out this page for info: http://msdn2.microsoft.com/en-us/library/sa91de1e(VS.80).aspx Particularly the following note:

“The proxy element defines a proxy server for an application. If this element is missing from the configuration file, then the .NET Framework will use the proxy settings in Internet Explorer.”

So – what we could assume from this is that if the setting is not there – all should work fine and dandy… well this would be true up to a point – and that point is authentication.

Authentication

Does the Proxy server authenticate using the default credentials of the user logged into windows? If so then we either want:

a) useDefaultCredentials=”true” in the default proxy config element, also see: http://geekswithblogs.net/mnf/archive/2006/03/08/71663.aspx

b) or we want to “WebRequest.DefaultWebProxy.Credentials = CredentialCache.DefaultCredentials;”

Credentials arnt stored in the Default Credentials? This is the situation you are in if have a user/pass box popup when you first navigate to a page in IE.

  NetworkCredential nc = new NetworkCredential("ProxyUser","ProxyPassword", "ProxyDomain");

  WebRequest.DefaultWebProxy.Credentials = nc;

Other interesting reading about a specific problem that you might be having:

http://geekswithblogs.net/mnf/archive/2006/09/13/91012.aspx

http://www.dotnet247.com/247reference/msgs/52/263150.aspx

Share
  • Digg
  • Twitter
  • Facebook
  • Identi.ca