2

WCF に ClientCredentials のカスタム実装があります。ここ (MSDN)に示されているように、ClientCredentials の基本プロパティの 2 つは ClientCertificate と ServiceCertificateです。

私の構成では、カスタム ClientCredentials が設定され、両方の証明書が定義されています。

        <endpointBehaviors>
            <behavior name="MyCustomEndpointBehavior">
                <clientCredentials type="MyApp.Security.CentralAuthClientCredentials, MyApp">
                    <clientCertificate findValue="localhost" x509FindType="FindBySubjectName" storeLocation="CurrentUser" storeName="My" />
                    <serviceCertificate>
                        <defaultCertificate findValue="localhost" x509FindType="FindBySubjectName" storeLocation="CurrentUser" storeName="My" />
                        <authentication certificateValidationMode="None" revocationMode="NoCheck" />
                    </serviceCertificate>
                </clientCredentials>
            </behavior>
        </endpointBehaviors>

この構成は、UserName 認証で完全に 100%機能していました。証明書を使用して、メッセージのユーザー名とパスワードを暗号化しました。次に、カスタム ClientCredentials に変更しました。

実行時に、CentralAuthClientCredentials に設定されるプロパティは次のとおりです。

this.ClientCertificate = System.ServiceModel.Security.X509CertificateInitiatorClientCredential
this.ClientCertificate.Certificate = null
this.ServiceCertificate = System.ServiceModel.Security.X509CertificateRecipientClientCredential
this.ServiceCertificate.DefaultCertificate = null

では、構成で定義されているクライアントとサービスの既定の証明書が、実際にインスタンス化されたオブジェクトに設定されていないのはなぜでしょうか? WCF が XML タグを完全に無視したようです。

おそらく資格情報のコンストラクターで、構成からそれらの証明書を手動で取得するために使用できるコードはありますか?

助けてくれてありがとう!


アップデート

私はアホです。私はそれを考え出した。WCF は実際には証明書セットを使用してインスタンスを正しく作成していましたが、私の wcf クライアントには、MSDN の例からコピーしたと思われる次の削除/追加シリーズがありました。

this.ChannelFactory.Endpoint.Behaviors.Remove<ClientCredentials>();
this.ChannelFactory.Endpoint.Behaviors.Add(new CentralAuthClientCredentials());
return base.Channel.MyServiceMethod();

古い資格情報を削除し、独自のカスタム資格情報を追加するには。ただし、これは証明書が設定されていない新しいインスタンスを作成していました! おっとっと!

4

1 に答える 1

1

これを回答済みとしてマークできるように、新しい資格情報を作成するクライアントからこのコードを削除するという独自のソリューションを追加しています。

this.ChannelFactory.Endpoint.Behaviors.Remove<ClientCredentials>();
this.ChannelFactory.Endpoint.Behaviors.Add(new CentralAuthClientCredentials());

Remove() を呼び出す代わりに、WCF によって既に設定されているものを使用します。

于 2009-03-19T11:39:55.427 に答える