【发布时间】:2011-07-22 23:43:55
【问题描述】:
我正在尝试将现有应用程序迁移到 Mono (v2.10.2)。
因此,我创建了一个带有 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();
在 Mono 中,应用程序在 CreateChannel 中失败并抛出异常:
System.InvalidOperationException:绑定不支持合同“IService1”允许的任何通道类型。
我调试到Mono源代码,发现问题是AsymmetricSecurityBindingElement.InitiatorTokenParameter == null。
我是 Mono 的新手,也许您可以向我指出涵盖该主题的文档/教程。
更新:
在 konrad.kruczynski 的帮助下,证书对象现在有了一个私钥。例外仍然相同。所以这不是证书存储问题。
【问题讨论】:
-
也许有人可以为我指出一种比在证书存储中搜索证书更好的方法来阅读证书。从 pfx 文件中读取它们对于我的目的来说是完美的。
-
我会认为这是一个错误。值得添加到 bugzilla,它们有时会很快得到修复。
-
我在单声道邮件列表中发布了同样的问题。
-
消息安全不受官方支持。所以我不会从单声道邮件列表中获得帮助。
-
我也有同样的需求,所以我对你在这里的成功很感兴趣。
标签: wcf mono certificate