创建 WCF 通道后更改客户端凭据

发布于 2024-10-02 23:20:31 字数 78 浏览 4 评论 0原文

我们构建的系统允许用户在创建 WCF 通道后更改其密码 - 有没有办法更改发送到服务器的凭据,而无需重新创建通道?

先感谢您。

The system we've built allows for a user to change their password after a WCF channel has been created - is there a way to change the credentials being sent through to the server without having to recreate the channel?

Thank you in advance.

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

春风十里 2024-10-09 23:20:31

如果通道已被使用,则凭证将变为只读且无法更改(如果凭证被修改,则会引发异常)。

如果通道尚未使用(并且关联通道工厂的状态为“已创建”或“正在打开”),则您可以通过以下方式更新凭据:

public void UpdateCredentials<T>(ClientBase<T> client, string username, string password)
{
  client.ClientCredentials.UserName.UserName = username;
  client.ClientCredentials.UserName.Password = password;
}

但是,根据您的问题,我猜测该通道已被使用。在这种情况下,恐怕您必须重新创建频道。

If the channel has already been used, then the credentials are made read only and cannot be changed (an exception is thrown if the credentials are modified).

If the channel has not been used (and the state of the associated channel factory is Created or Opening) then you can update the credentials in the following way:

public void UpdateCredentials<T>(ClientBase<T> client, string username, string password)
{
  client.ClientCredentials.UserName.UserName = username;
  client.ClientCredentials.UserName.Password = password;
}

However, from your question, I would guess that the channel has already been used. In which case you must re-create the channel I'm afraid.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文