对于基于Internet的应用,基于用户名和密码的认证方式是最为常用的,而WCF为你提供了不同模式的用户名认证方式。首先还是从用户凭证的表示说起。
基于用户名/密码的用户凭证通过类型UserNamePasswordClientCredential表示。而在ClientCredentials中,只读属性UserName表示这样一个用户凭证。你可以按照Windows凭证的方式为ChannelFactory<TChannel>或者ClientBase<TChannel>基于用户名/密码凭证。
class ClientCredentials
2: {
//其他成员
public UserNamePasswordClientCredential UserName { get; }
5: }
class UserNamePasswordClientCredential
7: {
//其他成员
string Password {get; set; }
string UserName { get; set; }
11: }