【发布时间】:2010-10-08 17:07:33
【问题描述】:
我在 WCF 中有一个 ClientCredentials 的自定义实现。 ClientCredentials 的两个基本属性是 ClientCertificate 和 ServiceCertificate,如 here (MSDN) 所示。
在我的配置中,我设置了自定义 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>
此配置完全 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();
删除旧凭据并添加我自己的自定义凭据。然而,这是一个没有设置证书的新实例!哎呀!
【问题讨论】:
-
你能显示正在使用的绑定吗?
-
您能否将您的解决方案发布到答案并接受它,这样它就不会出现在未回答的问题中?
标签: c# .net wcf credentials certificate