我在WCF中有一个ClientCredentials的自定义实现。ClientCredentials的两个基本属性是ClientCertificate和ServiceCertificate,如图所示
here (MSDN)
.
<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>
使用用户名身份验证。它使用证书对消息的用户名和密码进行加密。然后我更改为自定义ClientCredentials。
在运行时,以下是在我的CentralAuthClientCredentials上设置的属性:
this.ClientCertificate = System.ServiceModel.Security.X509CertificateInitiatorClientCredential
this.ClientCertificate.Certificate = null
this.ServiceCertificate = System.ServiceModel.Security.X509CertificateRecipientClientCredential
this.ServiceCertificate.DefaultCertificate = null
不
我可以在凭据的构造函数中使用一些代码来手动从配置中获取这些证书吗?
更新
思考
this.ChannelFactory.Endpoint.Behaviors.Remove<ClientCredentials>();
this.ChannelFactory.Endpoint.Behaviors.Add(new CentralAuthClientCredentials());
return base.Channel.MyServiceMethod();
删除旧凭据并添加我自己的自定义凭据。然而,这正在创建一个没有设置证书的新实例!哎呀!