问题描述:

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>

网友答案:

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>
网友答案:

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

网友答案:

From the information provided, it sounds as though the Windows XP machine on which this code works falls into one of the following categories:

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

This is common for smaller companies that would not invest in multiple proxies and don't want the extra latency of routing all traffic through their main campus.

It sounds like the Windows 7 location uses a proxy that does require authentication. As Coding Gorilla points out, your proxy settings are already configured under "Internet Options" in the control panel.

To verify this, you could check the "Internet Options" on the XP machine to see whether or not it has a proxy configured.

相关阅读:
Top