Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Proxy authentication required error when using a webservice

I've a .Net 4.0 windows application running on Windows 7 and Windows XP. One of the modules in the app connects to a url on the internet[say http://abc.com/xyz/MyWebService] using their web service.This functionality has been working until last week when I started to get this error message when invoking a method on the webservice

There was no endpoint listening at http://abc.com/xyz/MyWebService that could accept the message. This is often caused by an incorrect address or SOAP action. See InnerException, if present, for more details.And the InnerException was:HTTP Error 407 Proxy authentication required

I re-ran this code[on Windows 7] multiple times and I found out that this behavior is random...ie.sometimes am able to invoke webservice method on the server without any error.

Not sure whats going on behind the scenes and what could explain this random behavior. Also, this error does not come on a machine which has Windows XP that is located in a different geographical location on the company intranet.

Any ideas?

Note:When I added following node in my app.config, the error seems to have gone:

<system.net>
    <defaultProxy enabled="true" useDefaultCredentials="true">
    </defaultProxy>
</system.net>
like image 281
Jimmy Avatar asked Jun 24 '12 09:06

Jimmy


People also ask

What is a proxy authentication error?

http status codes. A 407 Proxy Authentication Required error indicates that the client needs to authenticate with a proxy server in order to access the requested resource. This is usually caused by incorrect proxy settings or by a firewall blocking access to the proxy server.

What is HTTP proxy authentication required?

The HTTP 407 Proxy Authentication Required client error status response code indicates that the request has not been applied because it lacks valid authentication credentials for a proxy server that is between the browser and the server that can access the requested resource.

How do I fix error 407 in Chrome?

Step 1: Check the URL. First, you'll want to make sure that you're entering the correct URL. This may sound silly, but a minor typo can lead to the HTTP 407 error. Therefore, you'll want to double-check the URL, clear your cache, and try revisiting the website.


2 Answers

I faced almost 2 weeks of pain for this issue at one of our client's end connecting our webservices.

You need to override System.Net configuration with a custom proxy module which implements IWebProxy

Step 1: Create an Assembly (DLL) Step 2: Add the following class to it

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.Configuration;

namespace MyProjectNameSpace.Utils.WebProxy
{
    public class CustomWebProxy : IWebProxy
    {
        public ICredentials Credentials
        {
            get
            {
                string _proxyUserName  = ConfigurationManager.AppSettings["ProxyUserName" ] as string ?? "";
                string _proxyPassword  = ConfigurationManager.AppSettings["ProxyPassword" ] as string ?? "";
                string _useProxyDomain = ConfigurationManager.AppSettings["UseProxyDomain"] as string ?? "";
                string _proxyDomain    = ConfigurationManager.AppSettings["ProxyDomain"   ] as string ?? "";

                return String.IsNullOrEmpty(_proxyDomain)
                    ? new NetworkCredential(_proxyUserName, _proxyPassword)
                    : new NetworkCredential(_proxyUserName, _proxyPassword, _proxyDomain);
            }
            set { }
        }

        public Uri GetProxy(Uri destination)
        {
            string _proxyServer = ConfigurationManager.AppSettings["ProxyServer"] as string ?? "";
            Uri result = new Uri(_proxyServer);
            return result;
        }

        public bool IsBypassed(Uri host)
        {
            return false;
        }
    }
}

Step 3: Compile to Release Mode Step 4: Refer the DLL to your WCF Client Project Step 5: Open the Web.Config or App.Config file for the WCF Client Project and add following configurations.

<appSettings>
        <add key="ProxyServer" value="http://192.168.1.254:9099"/>
        <add key="ProxyUserName" value="dipak.r"/>
        <add key="ProxyPassword" value="password"/>
        <add key="UseProxyDomain" value="true"/>
        <add key="ProxyDomain" value="DOMAINNAME"/>
</appSettings>

Add the following section or change it.

<system.net>
    <defaultProxy enabled="true" useDefaultCredentials="false">
      <module type="MyProjectNameSpace.Utils.WebProxy.CustomWebProxy, MyProjectNameSpace.Utils.WebProxy"/>
    </defaultProxy>
</system.net>
like image 178
DipakRiswadkar Avatar answered Sep 23 '22 07:09

DipakRiswadkar


I think this has nothing to do with your WCF service .

Its because of changing configuration of your firewall if you are sitting behind an ISA server or something

Look at the link below for furthur clarification

wcf-http-407-proxy-authentication-required

like image 41
Tabish Sarwar Avatar answered Sep 25 '22 07:09

Tabish Sarwar