ClientCredentials 类 
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
使用户能够配置客户端和服务凭据以及服务凭据身份验证设置,以用于通信的客户端。
public ref class ClientCredentials : System::ServiceModel::Description::IEndpointBehaviorpublic ref class ClientCredentials : System::ServiceModel::Security::SecurityCredentialsManager, System::ServiceModel::Description::IEndpointBehaviorpublic class ClientCredentials : System.ServiceModel.Description.IEndpointBehaviorpublic class ClientCredentials : System.ServiceModel.Security.SecurityCredentialsManager, System.ServiceModel.Description.IEndpointBehaviortype ClientCredentials = class
    interface IEndpointBehaviortype ClientCredentials = class
    inherit SecurityCredentialsManager
    interface IEndpointBehaviorPublic Class ClientCredentials
Implements IEndpointBehaviorPublic Class ClientCredentials
Inherits SecurityCredentialsManager
Implements IEndpointBehavior- 继承
- 
				ClientCredentials
- 继承
- 派生
- 实现
示例
下面的代码示例演示如何重写此类并实现你自己的包含自定义的安全令牌管理器的自定义客户端凭据。
重要
需要特别注意的是,将重写 CreateSecurityTokenManager 方法以创建自定义安全令牌管理器。 派生自 ClientCredentialsSecurityTokenManager的安全令牌管理器。 必须返回派生自 SecurityTokenProvider的自定义安全令牌提供程序才能创建实际的安全令牌。 如果不遵循此模式创建安全令牌,则您的应用程序将面临安全攻击风险,尤其是特权提升。 此编码模式确保在缓存通道工厂时使用正确的凭据。
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);
    }
}
Public Class MyClientCredentials
    Inherits ClientCredentials
    Private creditCardNumberValue As String
    Public Sub New() 
    
    End Sub
    
    ' Perform client credentials initialization.    
    Protected Sub New(ByVal other As MyClientCredentials) 
        MyBase.New(other)
        ' Clone fields defined in this class.
        Me.creditCardNumberValue = other.creditCardNumberValue
    
    End Sub
    Public Property CreditCardNumber() As String 
        Get
            Return Me.creditCardNumberValue
        End Get
        Set
            If value Is Nothing Then
                Throw New ArgumentNullException("value")
            End If
            Me.creditCardNumberValue = value
        End Set
    End Property
    Public Overrides Function CreateSecurityTokenManager() As SecurityTokenManager 
        ' Return your implementation of the SecurityTokenManager.
        Return New MyClientCredentialsSecurityTokenManager(Me)
    
    End Function
    
    Protected Overrides Function CloneCore() As ClientCredentials 
        ' Implement the cloning functionality.
        Return New MyClientCredentials(Me)
    
    End Function
End Class
注解
通过 ClientCredentials 类的 ClientCredentials 属性来访问 ClientBase<TChannel>。
向 ClientCredentials 集合中添加了一个 Behaviors 对象。 该 ClientCredentials 属性是一个 Facade (一个已知设计模式,) 该集合中的条目。 此类中的许多属性可返回主要由属性组成的对象。 以下对象可用于配置:您 get 该对象后,可通过调用其成员来将其用于 set 属性。
构造函数
| ClientCredentials() | 初始化 ClientCredentials 类的新实例。 | 
| ClientCredentials(ClientCredentials) | 此为复制构造函数。 | 
属性
| ClientCertificate | 获取一个对象,您可以使用该对象来提供客户端用于通过到服务的验证的 X.509 证书。 | 
| HttpDigest | 获取当前 HTTP 摘要凭据。 | 
| IssuedToken | 使用此属性可指定在联系本地安全令牌服务时要使用的终结点地址和绑定。 某服务需要使用已颁发令牌的身份验证,但该服务的策略(表示为客户端上的绑定)未显式指定如何和在什么位置获取已颁发的令牌时,会使用此信息。 | 
| Peer | 控制对等节点用于使自身通过到网格中的其他节点的认证的凭据,以及对等节点用于认证其他对等节点的对等节点。 | 
| SecurityTokenHandlerCollectionManager | 获取或设置用于客户端凭据的安全令牌处理程序。 | 
| ServiceCertificate | 获取用于指定服务的 X.509 证书的对象。 | 
| SupportInteractive | 获取或设置指示是否允许系统在必要时交互式提示用户输入凭据。 例如,在中间层方案中,可能需要将其设置为  | 
| UseIdentityConfiguration | 获取或设置客户端凭据是否使用标识配置。 | 
| UserName | 获取一个凭据对象,您可以使用该对象来设置客户端用于使自身通过到服务的身份验证的用户名和密码。 | 
| Windows | 获取用于控制客户端用于使自身通过到服务的身份认证的 Windows 凭据的对象。 | 
方法
| ApplyClientBehavior(ServiceEndpoint, ClientRuntime) | 将指定客户端行为应用于终结点。 | 
| Clone() | 创建此 ClientCredentials 实例的新副本。 | 
| CloneCore() | 创建此 ClientCredentials 实例的新副本。 | 
| CreateSecurityTokenManager() | 为此实例创建安全令牌管理器。 此方法很少显式调用;它主要用于扩展方案,由系统自已调用。 | 
| Equals(Object) | 确定指定对象是否等于当前对象。(继承自 Object) | 
| GetHashCode() | 作为默认哈希函数。(继承自 Object) | 
| GetInfoCardSecurityToken(Boolean, CardSpacePolicyElement[], SecurityTokenSerializer) | 使用 CardSpace 系统和指定的策略链和令牌序列化程序生成并返回安全令牌。 | 
| GetType() | 获取当前实例的 Type。(继承自 Object) | 
| MemberwiseClone() | 创建当前 Object 的浅表副本。(继承自 Object) | 
| ToString() | 返回表示当前对象的字符串。(继承自 Object) |