ClientCredentials 類別

定義

讓使用者設定可用於通訊之用戶端的用戶端和服務認證,以及服務認證驗證設定。

public ref class ClientCredentials : System::ServiceModel::Description::IEndpointBehavior
public ref class ClientCredentials : System::ServiceModel::Security::SecurityCredentialsManager, System::ServiceModel::Description::IEndpointBehavior
public class ClientCredentials : System.ServiceModel.Description.IEndpointBehavior
public class ClientCredentials : System.ServiceModel.Security.SecurityCredentialsManager, System.ServiceModel.Description.IEndpointBehavior
type ClientCredentials = class
    interface IEndpointBehavior
type ClientCredentials = class
    inherit SecurityCredentialsManager
    interface IEndpointBehavior
Public Class ClientCredentials
Implements IEndpointBehavior
Public 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 是已知設計 模式 (該 集合中專案) 的外觀。 這個類別中的大多數屬性都會傳回組成多數屬性的物件。 這些物件可以用於組態:當 get 物件之後,您就可以呼叫其成員,使用它來 set 屬性。

建構函式

ClientCredentials()

初始化 ClientCredentials 類別的新執行個體。

ClientCredentials(ClientCredentials)

這是複製建構函式。

屬性

ClientCertificate

取得您可以用來提供 X.509 憑證的物件,而該憑證將由用戶端用於向服務進行驗證。

HttpDigest

取得目前的 HTTP 摘要式認證。

IssuedToken

使用這個屬性,即可指定要在連絡本機安全性權杖服務時使用的端點位址和繫結。 當服務要求以發行的權杖進行驗證,但是服務的原則 (表示為用戶端上的繫結) 卻未明確指定如何及從何處取得發行的權杖時,就會使用這份資訊。

Peer

控制對等節點用於向網狀結構中其他節點驗證其本身的認證,以及對等節點用來驗證其他對等節點的驗證設定。

SecurityTokenHandlerCollectionManager

取得或設定用戶端認證的安全性權杖處理常式。

ServiceCertificate

取得用於指定服務之 X.509 憑證的物件。

SupportInteractive

取得或設定值,這個值會指出是否允許系統在必要時以互動方式提示要求使用者提供認證。 例如,在中介層案例中,可能需要將這個設定為 false

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)

明確介面實作

IEndpointBehavior.AddBindingParameters(ServiceEndpoint, BindingParameterCollection)

將這個類別的執行個體新增至繫結參數集合。

IEndpointBehavior.ApplyDispatchBehavior(ServiceEndpoint, EndpointDispatcher)

實作端點上服務的修改或延伸。

IEndpointBehavior.Validate(ServiceEndpoint)

保留供未來使用。

適用於