我試圖將現有的應用程序遷移到Mono(v2.10.2)。Mono的WCF證書安全性
因此我創建了一個帶有BasicHttpBinding和消息安全性的測試WCF服務。客戶端與.NET完美協作,但在使用Mono運行時失敗。
客戶端工廠被實例如下:
//var certificate = CertificateUtil.GetCertificate(StoreLocation.LocalMachine,
// StoreName.My, X509FindType.FindBySubjectDistinguishedName, CertName, true);
var certificate = new X509Certificate2("certificate.pfx", "password");
var binding = new BasicHttpBinding();
binding.Security.Mode = BasicHttpSecurityMode.Message;
binding.Security.Message.ClientCredentialType = BasicHttpMessageCredentialType.Certificate;
var epa = new EndpointAddress(
new Uri("http://localhost:53076/Service1.svc"),
new X509CertificateEndpointIdentity(certificate));
var factory = new ChannelFactory<IService1>(binding, epa);
factory.Credentials.ServiceCertificate.DefaultCertificate = certificate;
factory.Credentials.ServiceCertificate.Authentication.CertificateValidationMode = X509CertificateValidationMode.None;
factory.Credentials.ServiceCertificate.Authentication.RevocationMode = X509RevocationMode.NoCheck;
factory.Credentials.ClientCertificate.Certificate = certificate;
var client = factory.CreateChannel();
在單聲道應用程序內CreateChannel拋出異常失敗:
System.InvalidOperationException:綁定不支持任何類型的信道的合同'IService1'允許。
我調試成單聲道源代碼,發現問題是AsymmetricSecurityBindingElement.InitiatorTokenParameter == null。
我是新來的單聲道,也許你可以指向我的文檔/教程涵蓋了這個話題。
UPDATE:
隨着konrad.kruczynski現在證書對象擁有私有密鑰的幫助。例外情況仍然如此。所以這不是證書商店問題。
也許有人可以指點我一個更好的閱讀證書的方法,而不是在證書存儲中搜索證書。從pfx文件中讀取它們對於我的目的來說是完美的。 –
請看我更新的帖子。 –
我會認爲這是一個錯誤。值得添加到bugzilla,他們有時快速修復。 –