ServiceCredentials.UserNameAuthentication Property

 

Gets the current user name/password authentication settings for this service.

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

public UserNamePasswordServiceCredential UserNameAuthentication { get; }

You can specify the settings of the user name/password authentication by calling members of the UserNamePasswordServiceCredential class on this instance, such as UserNamePasswordValidationMode and MembershipProvider.

The following code shows how to use this property to get the instance of the credential used by the 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();

.NET Framework
Available since 3.0
Return to top
Show: