6

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>
4

4 に答える 4

5

私は、Web サービスに接続しているクライアント側の 1 つで、この問題のためにほぼ 2 週間の苦痛に直面しました。

IWebProxy を実装するカスタム プロキシ モジュールで System.Net 構成をオーバーライドする必要があります。

手順 1: アセンブリ (DLL) を作成する 手順 2: 次のクラスを追加します

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

手順 3: リリース モードにコンパイルする 手順 4: DLL を WCF クライアント プロジェクトに参照する 手順 5: WCF クライアント プロジェクトの Web.Config または App.Config ファイルを開き、次の構成を追加します。

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

次のセクションを追加または変更します。

<system.net>
    <defaultProxy enabled="true" useDefaultCredentials="false">
      <module type="MyProjectNameSpace.Utils.WebProxy.CustomWebProxy, MyProjectNameSpace.Utils.WebProxy"/>
    </defaultProxy>
</system.net>
于 2012-07-03T12:59:34.263 に答える
2

これは、WCFサービスとは何の関係もないと思います。

ISAサーバーなどの背後に座っている場合は、ファイアウォールの構成が変更されるためです。

詳細については、以下のリンクをご覧ください

wcf-http-407-proxy-authentication-required

于 2012-06-26T19:52:56.037 に答える
0

提供された情報によると、このコードが動作する Windows XP マシンは、次のいずれかのカテゴリに分類されるようです。

  • プロキシを使用しない
  • この場所のプロキシは認証を必要としません (デフォルトのアカウントを使用します)

これは、複数のプロキシに投資せず、メイン キャンパスを介してすべてのトラフィックをルーティングするための余分な遅延を望まない小規模な企業によく見られます。

Windows 7 の場所では、認証が必要なプロキシが使用されているようです。Coding Gorillaが指摘しているように、プロキシ設定はコントロール パネルの [インターネット オプション] で既に構成されています。

これを確認するには、XP マシンの [インターネット オプション] をチェックして、プロキシが構成されているかどうかを確認します。

于 2012-06-26T19:00:40.013 に答える