如何使用配置在 WCF 客户端上设置用户名/密码?
我知道我可以通过代码来做到这一点
myClient.ClientCredentials.UserName.UserName = "User";
myClient.ClientCredentials.UserName.Password = "Password";
是否可以通过配置为客户端提供相同的东西?
I know I can do this through code using
myClient.ClientCredentials.UserName.UserName = "User";
myClient.ClientCredentials.UserName.Password = "Password";
Is it possible to provide the same thing for a client through configuration instead?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不幸的是,我认为这是不可能的。但是,您可以手动读取 .config 文件设置并以编程方式进行设置...
Unfortunately, I don't think it's possible. However, you can manually read your .config file settings and set it programmatically...
开箱即用是不可能的。更重要的是,它也不是很安全。
任何有权访问配置文件的人都将拥有该服务的凭据。对于客户端应用程序,这将是任何可以运行该程序的人,因为他们将具有对应用程序安装位置的读取访问权限。
It's not possible out of the box. More importantly it wouldn't be very secure either.
Anyone who has access to the config file would then have the credentials for the service. For a client application, this will be anyone who can run the program as they will have read access to the application install location.