即时更改 WCF 服务的证书,无需停机

发布于 2024-10-30 22:10:57 字数 949 浏览 1 评论 0原文

我一直在研究一种在服务开始侦听其连接后更改 WCF 中的 IssuedTokenAuthentication 证书的方法。我知道我可以通过进入 web.config 然后重置服务来更改证书,以便它加载新设置,但我需要在没有任何停机时间的情况下即时执行此操作。

我知道我可以通过以下方式获取当前的 ServiceHost 实例:

ServiceHost host = (ServiceHost)OperationContext.Current.Host;

然后我可以通过以下方式访问其服务证书:

host.Credentials.IssuedTokenAuthentication.KnownCertificates

但一旦服务运行,这将不起作用,因为返回的证书列表将变为只读。

我看到的另一种方法是走描述路线,但这似乎也是只读的:

host.Description.Behaviors.Find<ServiceCredentials>().IssuedTokenAuthentication.KnownCertificates;

在 web.config 的以下位置可以找到相同的证书列表:

<configuration>
  <system.serviceModel>
    <behaviors>
      <serviceBehaviors>
        <behavior>              
          <serviceCredentials>
              <serviceCertificate/>

我陷入了这一点,我不认为实际上有办法访问这些证书的可写列表。这是真的吗,有人可以证实吗,或者有什么办法吗?

谢谢!

I've been researching a way of changing IssuedTokenAuthentication certs in a WCF after the service has started listening to its connection. I know that I could change the certs just by going into the web.config and then resetting the service so it loads the new settings, but I need to do it on the fly without any downtime.

I know that I could get the current ServiceHost instance by doing:

ServiceHost host = (ServiceHost)OperationContext.Current.Host;

and then I could access its service certs through:

host.Credentials.IssuedTokenAuthentication.KnownCertificates

but that doesn't work once the service is running, as the list of certificates returned becomes ReadOnly.

The other way I've seen is to go the Description route, but that seems to be read only as well:

host.Description.Behaviors.Find<ServiceCredentials>().IssuedTokenAuthentication.KnownCertificates;

The same cert list would be found in the following location of the web.config:

<configuration>
  <system.serviceModel>
    <behaviors>
      <serviceBehaviors>
        <behavior>              
          <serviceCredentials>
              <serviceCertificate/>

I'm stuck at this point, I don't think there's actually a way to access a writable list of those certs. Is that true, can anybody confirm, or is there a way?

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文