Proxy authentication requires error while using web service

I have a .Net 4.0 application running on Windows 7 and Windows XP. One of the application modules connects to a URL on the Internet [say http://abc.com/xyz/MyWebService] using its web service. This functionality works until the last week, when I started receiving this error message when a method call in webservice

There was no endpoint listening at http://abc.com/xyz/MyWebService which could receive the message. This is often caused by the wrong address or SOAP action. See InnerException, if present, for more information. details.And InnerException: HTTP Error 407 Proxy Authentication Required

I re-run this code [on Windows 7] several times and I found out that this behavior is random ... ie.sometimes can call the webservice method on the server without any errors.

Not sure what is going on behind the scenes and what might explain this random behavior. In addition, this error does not occur on a Windows XP computer that is located in a different geographical location on the company's intranet.

Any ideas?

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

<system.net> <defaultProxy enabled="true" useDefaultCredentials="true"> </defaultProxy> </system.net> 
+6
source share
3 answers

I faced almost two weeks of pain for this problem on one of our clients, linking our web services.

You need to override System.Net configuration with a custom proxy module that 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 into release mode Step 4: access the WCF client project in the DLL. Step 5. Open the Web.Config or App.Config file for the WCF client project and add the 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> 
+5
source

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

Due to reconfiguration of your firewall if you are sitting at an ISA server or something

Take a look at the link below to clarify the furth.

wcf-http-407-proxy-authentication-required

+3
source

From the information provided, it seems that the Windows XP machine that runs this code falls into one of the following categories:

  • Does not use a proxy server
  • The proxy for this location does not require authentication (uses the default account)

This is a common occurrence for small companies that will not invest in several proxy servers and do not want unnecessary latency to route all traffic through their main campus.

It looks like the Windows 7 location is using a proxy server that requires authentication. As Gorilla Encoding points out, your proxy settings are already configured in the "Internet Options" section of the control panel.

To verify this, you can check Internet Options on XP to see if the proxy is configured.

0
source

Source: https://habr.com/ru/post/918866/


All Articles