我一直在研究在服务开始侦听其连接后在WCF中更改IssuedTokenAuthentication证书的方法。我知道我可以通过进入web.config然后重置服务来更改证书,以便加载新的设置,但我需要在没有任何停机的情况下即时完成。
我知道我可以通过以下方式获取当前的ServiceHost实例:
ServiceHost host = (ServiceHost)OperationContext.Current.Host;
然后我可以通过以下方式访问其服务证书:
host.Credentials.IssuedTokenAuthentication.KnownCertificates
但是一旦服务运行,这不起作用,因为返回的证书列表变为ReadOnly。
我看到的另一种方法是去描述路线,但这似乎也是只读的:
host.Description.Behaviors.Find<ServiceCredentials>().IssuedTokenAuthentication.KnownCertificates;
可以在web.config的以下位置找到相同的证书列表:
<configuration>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior>
<serviceCredentials>
<serviceCertificate/>
我在这一点上陷入困境,我认为实际上没有办法访问这些证书的可写列表。这是真的,任何人都可以确认,或者有办法吗?
谢谢!