简体   繁体   中英

How do you set a username / password on a WCF Client using configuration?

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?

Unfortunately, I don't think it's possible. However, you can manually read your.config file settings and set it programmatically...

clientCredentials.UserName.UserName = ConfigurationManager.AppSettings["username"];
clientCredentials.UserName.Password = ConfigurationManager.AppSettings["password"];

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM