UserNamePasswordServiceCredential Class
This class is used to configure how the service authenticates users that use user name/password authentication and to configure the caching of logon tokens.
Assembly: System.ServiceModel (in System.ServiceModel.dll)
If none of the bindings used by a service is configured for user name/password-based authentication, the relevant properties for this class are ignored. These properties include the CustomUserNamePasswordValidator, IncludeWindowsGroups, MembershipProvider, and UserNamePasswordValidationMode properties.
If none of the bindings used by a service is configured to use Windows authentication for user name/password, the settings related to caching of logon tokens are ignored. These settings include the CachedLogonTokenLifetime, CacheLogonTokens, and MaxCachedLogonTokens properties.
The following example prints the values of the UserNamePasswordServiceCredential properties for a service.
// Create a service host. Uri httpUri = new Uri("http://localhost/Calculator"); ServiceHost sh = new ServiceHost(typeof(Calculator), httpUri); // Create a binding that uses a username/password credential. WSHttpBinding b = new WSHttpBinding(SecurityMode.Message); b.Security.Message.ClientCredentialType = MessageCredentialType.UserName; // Add an endpoint. sh.AddServiceEndpoint(typeof(ICalculator), b, "UserNamePasswordCalculator"); // Get a reference to the UserNamePasswordServiceCredential object. UserNamePasswordServiceCredential unpCredential = sh.Credentials.UserNameAuthentication; // Print out values. Console.WriteLine("IncludeWindowsGroup: {0}", unpCredential.IncludeWindowsGroups); Console.WriteLine("UserNamePasswordValidationMode: {0}", unpCredential.UserNamePasswordValidationMode); Console.WriteLine("CachedLogonTokenLifetime.Minutes: {0}", unpCredential.CachedLogonTokenLifetime.Minutes ); Console.WriteLine("CacheLogonTokens: {0}", unpCredential.CacheLogonTokens ); Console.WriteLine("MaxCachedLogonTokens: {0}", unpCredential.MaxCachedLogonTokens ); Console.ReadLine();
Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003
The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.