Web Service HTTP-407 Proxy Access Denied Error

Summary
When calling a web service operation you get the following error: “The request failed with HTTP status 407: Proxy Access Denied.”Conditions:

  1. When you inspect System.Security.Principal.WindowsIdentity.GetCurrent() the returned WindowIdentity is the current user’s Windows account.
  2. The web service proxy’s Proxy is null: “webService.Proxy == null” I true.
  3. The web service’s Credentials might be set or not. You get the above error even though you’ve set the web service proxy’s Credentials from System.Net.CredentialCache.DefaultCredentials: “webService.Credentials = System.Net.CredentialCache.DefaultCredentials”.

Solution
If the web service proxy’s Proxy property is null, then assign the default WebProxy to it:

if ( webService.Proxy == null )
{
webService.Proxy = System.Net.WebProxy.GetDefaultProxy();
webService.Proxy.Credentials = System.Net.CredentialCache.DefaultCredentials;
}