[英]WCF certificates not being set on custom credentials
我在WCF中有一个ClientCredentials的自定义实现。 ClientCredentials的两个基本属性是ClientCertificate和ServiceCertificate,如此处所示(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%使用UserName身份验证。 它使用证书对消息的用户名和密码进行加密。 然后,我更改为自定义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();
删除旧凭证并添加我自己的自定义凭证。 但是,这是在创建没有设置证书的新实例! 哎呀!
为了将其标记为已回答,我添加了自己的解决方案,该解决方案是从客户端中删除此代码以生成新的凭据:
this.ChannelFactory.Endpoint.Behaviors.Remove<ClientCredentials>();
this.ChannelFactory.Endpoint.Behaviors.Add(new CentralAuthClientCredentials());
并使用WCF已设置的那个,而不是对其调用Remove()。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.