1

好的。我的 WCF REST 服务通过 HttpWebRequest 调用与客户端证书一起运行得很好。但是,如果我使用此代码,它将不起作用:

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());

我收到错误消息: 但是使用完全相同的客户端证书在完全相同的 urlThe HTTP request was forbidden with client authentication scheme 'Anonymous'. 调用完全相同的服务就可以了。HttpWebRequest

我也尝试过不使用所有 ServiceCertificate 的东西,但没有任何区别
有人可以告诉我我的 WCF 代码中遗漏了什么吗?

4

0 回答 0