This documentation is archived and is not being maintained.

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.


Namespace:  System.ServiceModel.Security
Assembly:  System.ServiceModel (in System.ServiceModel.dll)

public sealed class UserNamePasswordServiceCredential

The UserNamePasswordServiceCredential type exposes the following members.

Public propertyCachedLogonTokenLifetimeGets or sets the maximum length of time that a token is cached.
Public propertyCacheLogonTokensGets or sets a value that indicates whether logon tokens are cached.
Public propertyCustomUserNamePasswordValidatorGets or sets a custom user name and password validator.
Public propertyIncludeWindowsGroupsGets or sets a value that indicates whether Windows groups are included in the security context.
Public propertyMaxCachedLogonTokensGets or sets the maximum number of logon tokens to cache.
Public propertyMembershipProviderGets or sets the membership provider.
Public propertyUserNamePasswordValidationModeGets or sets the method of validating the user name and password.

Public methodEquals(Object)Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Protected methodFinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public methodGetHashCodeServes as a hash function for a particular type. (Inherited from Object.)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Protected methodMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)

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 = 
// Print out values.
Console.WriteLine("IncludeWindowsGroup: {0}", 
Console.WriteLine("UserNamePasswordValidationMode: {0}",
Console.WriteLine("CachedLogonTokenLifetime.Minutes: {0}",
    unpCredential.CachedLogonTokenLifetime.Minutes );
Console.WriteLine("CacheLogonTokens: {0}",
    unpCredential.CacheLogonTokens );
Console.WriteLine("MaxCachedLogonTokens: {0}",
    unpCredential.MaxCachedLogonTokens );


.NET Framework

Supported in: 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.