12

顧客が資格情報を持つプロキシを使用している場合、WCFサービスに接続するのに問題があります。生成されたクライアントプロキシにクレデンシャルを設定する方法が見つかりません。

Webサービスを利用すれば、プロキシを設定することができます。

4

3 に答える 3

2

これがあなたが探しているものかどうかは完全にはわかりませんが、どうぞ。

  MyClient client = new MyClient();
  client.ClientCredentials.UserName.UserName = "u";
  client.ClientCredentials.UserName.Password = "p";
于 2008-09-20T15:45:32.687 に答える
2

ネットワーク サービスではなく、Active Directory ユーザーを [アプリケーション プール] > [ID] に追加することで、これを解決しました。このユーザーは、プロキシ サーバー経由でインターネットを閲覧する権限を持つグループにも属しています。また、このユーザーをクライアント ホスト サーバーの IIS_WPG グループに追加します。

以下のコードでは、最初のビットが WCF サービスを使用してクライアントを認証します。2 番目のビットは、資格情報を内部プロキシ サーバーに渡し、クライアントが DMZ サーバーで WCF サービスを呼び出すことを想定しています。しかし、プロキシ部分が機能しているとは思いません。とにかくコードを残しています。

        // username token credentials
        var clientCredentials = new ClientCredentials();
        clientCredentials.UserName.UserName = ConfigurationManager.AppSettings["Client.Mpgs.Username"];
        clientCredentials.UserName.Password = ConfigurationManager.AppSettings["Client.Mpgs.Password"];
        proxy.ChannelFactory.Endpoint.Behaviors.Remove(typeof(ClientCredentials));
        proxy.ChannelFactory.Endpoint.Behaviors.Add(clientCredentials);

        // proxy credentials 
        //http://kennyw.com/indigo/143
        //http://blogs.msdn.com/b/stcheng/archive/2008/12/03/wcf-how-to-supply-dedicated-credentials-for-webproxy-authentication.aspx
        proxy.ChannelFactory.Credentials.Windows.ClientCredential = new System.Net.NetworkCredential
                                                                    (
                                                                        ConfigurationManager.AppSettings["Client.ProxyServer.Username"]
                                                                       , ConfigurationManager.AppSettings["Client.ProxyServer.Password"]
                                                                       , ConfigurationManager.AppSettings["Client.ProxyServer.DomainName"]
                                                                     );

私のweb.configでは、次のものを使用しました。

<system.net>
    <defaultProxy useDefaultCredentials="true">
        <proxy usesystemdefault="True" proxyaddress="http://proxyServer:8080/" bypassonlocal="False" autoDetect="False"  />     </defaultProxy>
</system.net>
<system.serviceModel>
    <bindings>
        <wsHttpBinding>
            <binding name="WSHttpBinding_ITest" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard" maxBufferPoolSize="524288" maxReceivedMessageSize="65536" messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true" allowCookies="false">
                <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384"/>
                <reliableSession ordered="true" inactivityTimeout="00:10:00" enabled="false"/>
                <security mode="TransportWithMessageCredential">
                    <transport clientCredentialType="None" proxyCredentialType="None" realm=""/>
                    <message clientCredentialType="UserName" negotiateServiceCredential="true" algorithmSuite="Default"/>
                </security>
            </binding>
        </wsHttpBinding>
    </bindings>
    <client>
        <endpoint address="https://wcfservice.organisation.com/test/test.svc" binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_ITest" contract="Test.Test" name="WSHttpBinding_ITest"/>
    </client>
</system.serviceModel>

上記のコードは、私のローカル マシンから動作します。コードを開発サーバーにアップロードすると、機能しません。プロキシ サーバーのログを確認したところ、以下のように表示されます。

2011-06-14 05:21:10 2 11.11.11.11 - - authentication_failed DENIED "Organisation/Finance" - 407 TCP_DENIED CONNECT - tcp wcfservice.organisation.com 443 / - - - 11.11.11.11 612 161 -

2011-06-14 05:21:10 6 11.11.11.152 ServerName$ - policy_denied DENIED "Organisation/Finance" - 403 TCP_DENIED CONNECT - tcp wcfservice.organisation.com 443 / - - - 11.11.11.205 185 361 -

スマート システム管理者の DF は、ネットワーク サービスではなく、Active Directory ユーザーを [アプリケーション プール] > [ID] に追加しました。このユーザーは、プロキシ サーバー経由でインターネットを閲覧する権限を持つグループにも属しています。また、このユーザーをクライアント ホスト サーバーの IIS_WPG グループに追加します。

これは私にとってはうまくいきました。

于 2011-06-15T07:01:23.167 に答える
1

これが探しているものかどうかはわかりませんが、以下はクライアント資格情報を使用して認証する実際のコード サンプルです。

    Dim client As ProductServiceClient = New ProductServiceClient("wsHttpProductService")
    client.ClientCredentials.UserName.UserName = "username"
    client.ClientCredentials.UserName.Password = "password"
    Dim ProductList As List(Of Product) = client.GetProducts()
    mView.Products = ProductList
    client.Close()
于 2008-09-20T15:44:46.790 に答える