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;
}

5 Responses to “Web Service HTTP-407 Proxy Access Denied Error”

  1. José Dunstan Says:

    The problem with this method is that Microsoft says it is already obsolete but has raised no concrete solution, does not indicate how they replace.

  2. openlandscape Says:

    @José:
    I solved this problem for .NET 1.1, so I can’t comment on the issue for .NET versions after that. I will do an updated post for .NET 2 & 3 when I need to solve it for those frameworks, or please let me know if you find the solution to this problem on those frameworks. I will update the post, and give you full credit. Thanks for letting us know that it was made obsolete for other .NET frameworks.

  3. Dani Says:

    I’ve solved this issue creating a new proxy. Thank you for this post, has helped me a lot.

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

  4. openlandscape Says:

    @Dani: Cool! Glad to have pointed you in the correct direction.

  5. Rahat Says:

    Thankx for ur help it have solved my access problem


Leave a Reply