ClientCredentials Class

Enables the user to configure client and service credentials as well as service credential authentication settings for use on the client side of communication.

System.Object
  System.ServiceModel.Security.SecurityCredentialsManager
    System.ServiceModel.Description.ClientCredentials

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

public class ClientCredentials : SecurityCredentialsManager, 
	IEndpointBehavior

The ClientCredentials type exposes the following members.

  NameDescription
Public methodSupported by Portable Class LibrarySupported in .NET for Windows Store appsClientCredentials()Initializes a new instance of the ClientCredentials class.
Protected methodSupported by Portable Class LibrarySupported in .NET for Windows Store appsClientCredentials(ClientCredentials)This is a copy constructor.
Top

  NameDescription
Public propertyClientCertificateGets an object that you can use to provide the X.509 certificate that the client uses to authenticate to the service.
Public propertySupported in .NET for Windows Store appsHttpDigestGets the current HTTP Digest credential.
Public propertyIssuedTokenUse this property to specify the endpoint address and binding to use when contacting your local Security Token Service. This information is used when a service requires authentication using an issued token, but the policy of the service (represented as a binding on the client) does not explicitly specify how and where to obtain the issued token.
Public propertyPeerControls the credentials that a peer node uses to authenticate itself to other nodes in the mesh, as well as authentication settings that a peer node uses to authenticate other peer nodes.
Public propertySecurityTokenHandlerCollectionManagerGets or sets the security token handler for the client credential.
Public propertyServiceCertificateGets an object used to specify a service's X.509 certificate.
Public propertySupportInteractiveGets or sets a value that indicates whether the system is allowed to interactively prompt the user for credentials when necessary. For example, setting it to false might be desired in middle-tier scenarios.
Public propertyUseIdentityConfigurationGets or sets whether the client credentials uses identity configuration.
Public propertySupported by Portable Class LibrarySupported in .NET for Windows Store appsUserNameGets a credential object that you can use to set the user name and password that the client uses to authenticate itself to the service.
Public propertySupported in .NET for Windows Store appsWindowsGets an object used to control the Windows credential that the client uses to authenticate itself to the service.
Top

  NameDescription
Public methodSupported in .NET for Windows Store appsApplyClientBehaviorApplies the specified client behavior to the endpoint.
Public methodSupported by Portable Class LibrarySupported in .NET for Windows Store appsCloneCreates a new copy of this ClientCredentials instance.
Protected methodSupported by Portable Class LibrarySupported in .NET for Windows Store appsCloneCoreCreates a new copy of this ClientCredentials instance.
Public methodCreateSecurityTokenManagerCreates a security token manager for this instance. This method is rarely called explicitly; it is primarily used in extensibility scenarios and is called by the system itself. (Overrides SecurityCredentialsManager.CreateSecurityTokenManager().)
Public methodSupported by Portable Class LibrarySupported in .NET for Windows Store appsEquals(Object)Determines whether the specified object is equal to the current object. (Inherited from Object.)
Protected methodSupported by Portable Class LibrarySupported in .NET for Windows Store appsFinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public methodSupported by Portable Class LibrarySupported in .NET for Windows Store appsGetHashCodeServes as the default hash function. (Inherited from Object.)
Protected methodGetInfoCardSecurityTokenGenerates and returns a security token using the CardSpace system and the specified policy chain and token serializer.
Public methodSupported by Portable Class LibrarySupported in .NET for Windows Store appsGetTypeGets the Type of the current instance. (Inherited from Object.)
Protected methodSupported by Portable Class LibrarySupported in .NET for Windows Store appsMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public methodSupported by Portable Class LibrarySupported in .NET for Windows Store appsToStringReturns a string that represents the current object. (Inherited from Object.)
Top

  NameDescription
Explicit interface implemetationPrivate methodSupported in .NET for Windows Store appsIEndpointBehavior.AddBindingParametersAdds this instance of this class to a binding parameter collection.
Explicit interface implemetationPrivate methodSupported in .NET for Windows Store appsIEndpointBehavior.ApplyDispatchBehaviorImplements a modification or extension of the service across an endpoint.
Explicit interface implemetationPrivate methodSupported in .NET for Windows Store appsIEndpointBehavior.ValidateReserved for future use.
Top

The ClientCredentials is accessed through the ClientCredentials property of the ClientBase<TChannel> class.

A ClientCredentials object is added to the Behaviors collection. The ClientCredentials property is a Façade (a well-known design pattern) over an entry in that collection. Many properties in this class return objects that consist mainly of properties. These objects can be used for configuration: once you get the object, you can use it to set properties by calling its members.

The following code sample shows how to override this class and implement your own custom client credentials that includes a custom security token manager.

Important noteImportant

It is important to note that the CreateSecurityTokenManager method is overridden to create a custom security token manager. The security token manager, derived from ClientCredentialsSecurityTokenManager. must return a custom security token provider, derived from [System.IdentityModel.Selectors.SecurityTokenProvider], to create the actual security token. If you do not follow this pattern for creating security tokens, your application will be at risk for security attacks, specifically elevation of privileges. This coding pattern ensures that the correct credentials are used when channel factories are cached.

public class MyClientCredentials : ClientCredentials
{
    string creditCardNumber;

    public MyClientCredentials()
    {
        // Perform client credentials initialization.
    }

    protected MyClientCredentials(MyClientCredentials other)
        : base(other)
    {
        // Clone fields defined in this class. 
        this.creditCardNumber = other.creditCardNumber;
    }

    public string CreditCardNumber
    {
        get
        {
            return this.creditCardNumber;
        }
        set
        {
            if (value == null)
            {
                throw new ArgumentNullException("value");
            }
            this.creditCardNumber = value;
        }
    }

    public override SecurityTokenManager CreateSecurityTokenManager()
    {
        // Return your implementation of the SecurityTokenManager. 
        return new MyClientCredentialsSecurityTokenManager(this);
    }

    protected override ClientCredentials CloneCore()
    {
        // Implement the cloning functionality. 
        return new MyClientCredentials(this);
    }
}

.NET Framework

Supported in: 4.5.2, 4.5.1, 4.5, 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Portable Class Library

Supported in: Portable Class Library

.NET for Windows Store apps

Supported in: Windows 8

.NET for Windows Phone apps

Supported in: Windows Phone 8.1, Windows Phone 8, Silverlight 8.1

Windows Phone 8.1, Windows Phone 8, Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

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.
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft