わかった。HttpWebRequest 呼び出しを介してクライアント証明書を使用して、WCF REST サービスを正常に実行しています。ただし、このコードを使用すると機能しません。
ServicePointManager.ServerCertificateValidationCallback += (sender, certificate, chain, errors) => true;
var factory = new WebChannelFactory<IMyContract>(new Uri(MyUrl));
var cc = factory.Endpoint.Behaviors.Find<ClientCredentials>();
cc.ClientCertificate.SetCertificate(StoreLocation.LocalMachine, StoreName.My, X509FindType.FindBySubjectName,MySubjectName);
cc.ServiceCertificate.Authentication.CertificateValidationMode = X509CertificateValidationMode.None;
cc.ServiceCertificate.Authentication.RevocationMode = X509RevocationMode.NoCheck;
cc.ServiceCertificate.Authentication.TrustedStoreLocation = StoreLocation.LocalMachine;
cc.ServiceCertificate.SetDefaultCertificate(StoreLocation.LocalMachine, StoreName.My, X509FindType.FindBySubjectName, MyOtherSubjectName);
_svc = factory.CreateChannel();
var result1 = _svc.Post(GetMyPostObject());
エラーが発生します:
しかし、まったく同じクライアント証明書を使用して、まったく同じURLでまったく同じサービスThe HTTP request was forbidden with client authentication scheme 'Anonymous'.
を
呼び出すと、問題なく動作します。HttpWebRequest
私も ServiceCertificate のものをすべて使わずに試してみましたが、違いはありませんでした
。WCF コードから何が欠けているのか誰か教えてもらえますか?