Vorgehensweise: Erstellen eines SecurityBindingElement für einen angegebenen Authentifizierungsmodus

Windows Communication Foundation (WCF) stellt verschiedene Modi bereit, mit denen sich Clients und Dienste gegenseitig authentifizieren. Sie können Sicherheitsbindungselemente für diese Authentifizierungsmodi erstellen. Dazu verwenden Sie statische Methoden für die SecurityBindingElement-Klasse oder die Konfiguration, wie im folgenden Beispiel dargestellt.

Weitere Informationen über zu den 18 Authentifizierungsmodi finden Sie unter SecurityBindingElement-Authentifizierungsmodi.

Beispiel

Im folgenden Codebeispiel werden Methoden zum Erstellen von Bindungen für die verschiedenen Authentifizierungsmodi veranschaulicht.

Aa702632.note(de-de,VS.100).gifHinweis:
Nachdem eine Instanz des SecurityBindingElement-Objekts erstellt wurde, sind einige Eigenschaften unveränderlich, wie beispielsweise KeyType und MessageSecurityVersion. set für diese Eigenschaften aufzurufen, hat keinen Effekt.

' These public methods create custom bindings based on the built-in 
' authentication modes that use the static methods of 
' the System.ServiceModel.Channels.SecurityBindingElement class.
Public Shared Function CreateAnonymousForCertificateBinding() As Binding 
    Dim bec As New BindingElementCollection()
    bec.Add(SecurityBindingElement.CreateAnonymousForCertificateBindingElement())
    bec.Add(New TextMessageEncodingBindingElement())
    bec.Add(New HttpTransportBindingElement())
    Return New CustomBinding(bec)
End Function 


Public Shared Function CreateAnonymousForSslNegotiatedBinding() As Binding 
    Dim bec As New BindingElementCollection()
    bec.Add(SecurityBindingElement.CreateSslNegotiationBindingElement(False))
    bec.Add(New TextMessageEncodingBindingElement())
    bec.Add(New HttpTransportBindingElement())
    Return New CustomBinding(bec)
End Function         

Public Shared Function CreateCertificateOverTransportBinding() As Binding 
    Dim bec As New BindingElementCollection()
    bec.Add(SecurityBindingElement.CreateCertificateOverTransportBindingElement())
    bec.Add(New TextMessageEncodingBindingElement())
    bec.Add(New HttpsTransportBindingElement())
    Return New CustomBinding(bec)
End Function 

Public Shared Function CreateIssuedTokenBinding() As Binding 
    Dim bec As New BindingElementCollection()
    bec.Add(SecurityBindingElement.CreateIssuedTokenBindingElement( _
            New IssuedSecurityTokenParameters()))
    bec.Add(New TextMessageEncodingBindingElement())
    bec.Add(New HttpTransportBindingElement())
    Return New CustomBinding(bec)
End Function         

Public Shared Function CreateIssuedTokenForCertificateBinding() As Binding 
    Dim bec As New BindingElementCollection()
    bec.Add(SecurityBindingElement. _
        CreateIssuedTokenForCertificateBindingElement( _
        New IssuedSecurityTokenParameters()))
    bec.Add(New TextMessageEncodingBindingElement())
    bec.Add(New HttpTransportBindingElement())
    Return New CustomBinding(bec)
End Function 

Public Shared Function CreateIssuedTokenForSslNegotiatedBinding() As Binding 
    Dim bec As New BindingElementCollection()
    bec.Add(SecurityBindingElement. _
        CreateIssuedTokenForSslBindingElement( _
        New IssuedSecurityTokenParameters()))
    bec.Add(New TextMessageEncodingBindingElement())
    bec.Add(New HttpTransportBindingElement())
    Return New CustomBinding(bec)
End Function 

Public Shared Function CreateIssuedTokenOverTransportBinding() As Binding 
    Dim bec As New BindingElementCollection()
    bec.Add(SecurityBindingElement. _
       CreateIssuedTokenOverTransportBindingElement( _
          New IssuedSecurityTokenParameters()))
    bec.Add(New TextMessageEncodingBindingElement())
    bec.Add(New HttpsTransportBindingElement())
    Return New CustomBinding(bec)
End Function         

Public Shared Function CreateKerberosBinding() As Binding 
    Dim bec As New BindingElementCollection()
    bec.Add(SecurityBindingElement.CreateKerberosBindingElement())
    bec.Add(New TextMessageEncodingBindingElement())
    bec.Add(New HttpTransportBindingElement())
    Return New CustomBinding(bec)
End Function 

Public Shared Function CreateKerberosOverTransportBinding() As Binding 
    Dim bec As New BindingElementCollection()
    bec.Add(SecurityBindingElement. _
        CreateKerberosOverTransportBindingElement())
    bec.Add(New TextMessageEncodingBindingElement())
    bec.Add(New HttpsTransportBindingElement())
    Return New CustomBinding(bec)
End Function 

Public Shared Function CreateMutualCertificateBinding() As Binding 
    Dim bec As New BindingElementCollection()
    bec.Add(SecurityBindingElement.CreateMutualCertificateBindingElement())
    bec.Add(New TextMessageEncodingBindingElement())
    bec.Add(New HttpTransportBindingElement())
    Return New CustomBinding(bec)
End Function 

Public Shared Function CreateMutualCertificateDuplexBinding() As Binding 
    Dim bec As New BindingElementCollection()
    bec.Add(SecurityBindingElement. _
        CreateMutualCertificateDuplexBindingElement())
    bec.Add(New CompositeDuplexBindingElement())
    bec.Add(New OneWayBindingElement())
    bec.Add(New TextMessageEncodingBindingElement())
    bec.Add(New HttpTransportBindingElement())
    Return New CustomBinding(bec)
End Function 

Public Shared Function CreateMutualSslNegotiatedBinding() As Binding 
    Dim bec As New BindingElementCollection()
    bec.Add(SecurityBindingElement. _
        CreateSslNegotiationBindingElement(True))
    bec.Add(New TextMessageEncodingBindingElement())
    bec.Add(New HttpTransportBindingElement())
    Return New CustomBinding(bec)
End Function 

Public Shared Function CreateSecureConversationBinding() As Binding 
    Dim bec As New BindingElementCollection()
    bec.Add(SecurityBindingElement. _
        CreateSecureConversationBindingElement( _
        SecurityBindingElement.CreateSspiNegotiationBindingElement()))
    bec.Add(New TextMessageEncodingBindingElement())
    bec.Add(New HttpTransportBindingElement())
    Return New CustomBinding(bec)
End Function 

Public Shared Function CreateSspiNegotiatedBinding() As Binding 
    Dim bec As New BindingElementCollection()
    bec.Add(SecurityBindingElement.CreateSspiNegotiationBindingElement())
    bec.Add(New TextMessageEncodingBindingElement())
    bec.Add(New HttpTransportBindingElement())
    Return New CustomBinding(bec)
End Function 


Public Shared Function CreateSspiNegotiatedOverTransportBinding() As Binding 
    Dim bec As New BindingElementCollection()
    bec.Add(SecurityBindingElement. _
        CreateSspiNegotiationOverTransportBindingElement())
    bec.Add(New TextMessageEncodingBindingElement())
    bec.Add(New HttpsTransportBindingElement())
    Return New CustomBinding(bec)
End Function 

Public Shared Function CreateUserNameForCertificateBinding() As Binding 
    Dim bec As New BindingElementCollection()
    bec.Add(SecurityBindingElement.CreateUserNameForCertificateBindingElement())
    bec.Add(New TextMessageEncodingBindingElement())
    bec.Add(New HttpTransportBindingElement())
    Return New CustomBinding(bec)
End Function 

Public Shared Function CreateUserNameForSslNegotiatedBinding() As Binding 
    Dim bec As New BindingElementCollection()
    bec.Add(SecurityBindingElement.CreateUserNameForSslBindingElement())
    bec.Add(New TextMessageEncodingBindingElement())
    bec.Add(New HttpTransportBindingElement())
    Return New CustomBinding(bec)

End Function 'CreateUserNameForSslNegotiatedBinding


Public Shared Function CreateUserNameOverTransportBinding() As Binding 
    Dim bec As New BindingElementCollection()
    bec.Add(SecurityBindingElement.CreateUserNameOverTransportBindingElement())
    bec.Add(New TextMessageEncodingBindingElement())
    bec.Add(New HttpsTransportBindingElement())
    Return New CustomBinding(bec)

End Function 
// These public methods create custom bindings based on the built-in 
// authentication modes that use the static methods of 
// the System.ServiceModel.Channels.SecurityBindingElement class.
public static Binding CreateAnonymousForCertificateBinding()
{
    BindingElementCollection bec = new BindingElementCollection();
    bec.Add(SecurityBindingElement.
        CreateAnonymousForCertificateBindingElement());
    bec.Add(new TextMessageEncodingBindingElement());
    bec.Add(new HttpTransportBindingElement());
    return new CustomBinding(bec);
}

public static Binding CreateAnonymousForSslNegotiatedBinding()
{
    BindingElementCollection bec = new BindingElementCollection();
    bec.Add(SecurityBindingElement.
        CreateSslNegotiationBindingElement(false));
    bec.Add(new TextMessageEncodingBindingElement());
    bec.Add(new HttpTransportBindingElement());
    return new CustomBinding(bec);
}

public static Binding CreateCertificateOverTransportBinding()
{
    BindingElementCollection bec = new BindingElementCollection();
    bec.Add(SecurityBindingElement.
        CreateCertificateOverTransportBindingElement());
    bec.Add(new TextMessageEncodingBindingElement());
    bec.Add(new HttpsTransportBindingElement());
    return new CustomBinding(bec);
}

public static Binding CreateIssuedTokenBinding()
{
    BindingElementCollection bec = new BindingElementCollection();
    bec.Add(SecurityBindingElement.
        CreateIssuedTokenBindingElement(
        new IssuedSecurityTokenParameters()));
    bec.Add(new TextMessageEncodingBindingElement());
    bec.Add(new HttpTransportBindingElement());
    return new CustomBinding(bec);
}

public static Binding CreateIssuedTokenForCertificateBinding()
{
    BindingElementCollection bec = new BindingElementCollection();
    bec.Add(SecurityBindingElement.
        CreateIssuedTokenForCertificateBindingElement(
        new IssuedSecurityTokenParameters()));
    bec.Add(new TextMessageEncodingBindingElement());
    bec.Add(new HttpTransportBindingElement());
    return new CustomBinding(bec);
}

public static Binding CreateIssuedTokenForSslNegotiatedBinding()
{
    BindingElementCollection bec = new BindingElementCollection();
    bec.Add(SecurityBindingElement.
        CreateIssuedTokenForSslBindingElement(
        new IssuedSecurityTokenParameters()));
    bec.Add(new TextMessageEncodingBindingElement());
    bec.Add(new HttpTransportBindingElement());
    return new CustomBinding(bec);
}

public static Binding CreateIssuedTokenOverTransportBinding()
{
    BindingElementCollection bec = new BindingElementCollection();
    bec.Add(SecurityBindingElement.
        CreateIssuedTokenOverTransportBindingElement(
        new IssuedSecurityTokenParameters()));
    bec.Add(new TextMessageEncodingBindingElement());
    bec.Add(new HttpsTransportBindingElement());
    return new CustomBinding(bec);
}

public static Binding CreateKerberosBinding()
{
    BindingElementCollection bec = new BindingElementCollection();
    bec.Add(SecurityBindingElement.CreateKerberosBindingElement());
    bec.Add(new TextMessageEncodingBindingElement());
    bec.Add(new HttpTransportBindingElement());
    return new CustomBinding(bec);
}

public static Binding CreateKerberosOverTransportBinding()
{
    BindingElementCollection bec = new BindingElementCollection();
    bec.Add(SecurityBindingElement.
        CreateKerberosOverTransportBindingElement());
    bec.Add(new TextMessageEncodingBindingElement());
    bec.Add(new HttpsTransportBindingElement());
    return new CustomBinding(bec);
}

public static Binding CreateMutualCertificateBinding()
{
    BindingElementCollection bec = new BindingElementCollection();
    bec.Add(SecurityBindingElement.
        CreateMutualCertificateBindingElement());
    bec.Add(new TextMessageEncodingBindingElement());
    bec.Add(new HttpTransportBindingElement());
    return new CustomBinding(bec);
}

public static Binding CreateMutualCertificateDuplexBinding()
{
    BindingElementCollection bec = new BindingElementCollection();
    bec.Add(SecurityBindingElement.
        CreateMutualCertificateDuplexBindingElement());
    bec.Add(new CompositeDuplexBindingElement());
    bec.Add(new OneWayBindingElement());
    bec.Add(new TextMessageEncodingBindingElement());
    bec.Add(new HttpTransportBindingElement());
    return new CustomBinding(bec);
}

public static Binding CreateMutualSslNegotiatedBinding()
{
    BindingElementCollection bec = new BindingElementCollection();
    bec.Add(SecurityBindingElement.
        CreateSslNegotiationBindingElement(true));
    bec.Add(new TextMessageEncodingBindingElement());
    bec.Add(new HttpTransportBindingElement());
    return new CustomBinding(bec);
}

public static Binding CreateSecureConversationBinding()
{
    BindingElementCollection bec = new BindingElementCollection();
    bec.Add(SecurityBindingElement.
        CreateSecureConversationBindingElement(
        SecurityBindingElement.CreateSspiNegotiationBindingElement()));
    bec.Add(new TextMessageEncodingBindingElement());
    bec.Add(new HttpTransportBindingElement());
    return new CustomBinding(bec);
}

public static Binding CreateSspiNegotiatedBinding()
{
    BindingElementCollection bec = new BindingElementCollection();
    bec.Add(SecurityBindingElement.CreateSspiNegotiationBindingElement());
    bec.Add(new TextMessageEncodingBindingElement());
    bec.Add(new HttpTransportBindingElement());
    return new CustomBinding(bec);
}

public static Binding CreateSspiNegotiatedOverTransportBinding()
{
    BindingElementCollection bec = new BindingElementCollection();
    bec.Add(SecurityBindingElement.
        CreateSspiNegotiationOverTransportBindingElement());
    bec.Add(new TextMessageEncodingBindingElement());
    bec.Add(new HttpsTransportBindingElement());
    return new CustomBinding(bec);
}

public static Binding CreateUserNameForCertificateBinding()
{
    BindingElementCollection bec = new BindingElementCollection();
    bec.Add(SecurityBindingElement.
        CreateUserNameForCertificateBindingElement());
    bec.Add(new TextMessageEncodingBindingElement());
    bec.Add(new HttpTransportBindingElement());
    return new CustomBinding(bec);
}

public static Binding CreateUserNameForSslNegotiatedBinding()
{
    BindingElementCollection bec = new BindingElementCollection();
    bec.Add(SecurityBindingElement.CreateUserNameForSslBindingElement());
    bec.Add(new TextMessageEncodingBindingElement());
    bec.Add(new HttpTransportBindingElement());
    return new CustomBinding(bec);
}

public static Binding CreateUserNameOverTransportBinding()
{
    BindingElementCollection bec = new BindingElementCollection();
    bec.Add(SecurityBindingElement.
        CreateUserNameOverTransportBindingElement());
    bec.Add(new TextMessageEncodingBindingElement());
    bec.Add(new HttpsTransportBindingElement());
    return new CustomBinding(bec);
}

Siehe auch

Konzepte

SecurityBindingElement-Authentifizierungsmodi
Vorgehensweise: Erstellen einer benutzerdefinierten Bindung mit dem SecurityBindingElement