SpnEndpointIdentity Constructors

Definition

Initializes a new instance of SpnEndpointIdentity.

Overloads

SpnEndpointIdentity(Claim)

Initializes a new instance of SpnEndpointIdentity with the specified identity claim.

SpnEndpointIdentity(String)

Initializes a new instance of SpnEndpointIdentity with the specified service principal name (SPN).

SpnEndpointIdentity(Claim)

Initializes a new instance of SpnEndpointIdentity with the specified identity claim.

public:
 SpnEndpointIdentity(System::IdentityModel::Claims::Claim ^ identity);
public SpnEndpointIdentity (System.IdentityModel.Claims.Claim identity);
new System.ServiceModel.SpnEndpointIdentity : System.IdentityModel.Claims.Claim -> System.ServiceModel.SpnEndpointIdentity
Public Sub New (identity As Claim)

Parameters

identity
Claim

The identity for this service principal name (SPN).

Exceptions

identity is null.

The claim type of identity is not Spn.

Examples

The following code shows how to create identities from a set of claims.

private SpnEndpointIdentity CreateIdentityFromClaimSet(ClaimSet claims)
{
    foreach (Claim claim in claims.FindClaims(null, Rights.Identity))
    {
        return new SpnEndpointIdentity(claim);
    }
    return null;
}
Private Function CreateIdentityFromClaimSet(ByVal claims As ClaimSet) As SpnEndpointIdentity
    For Each claim As Claim In claims.FindClaims(Nothing, Rights.Identity)
        Return New SpnEndpointIdentity(claim)
    Next claim
    Return Nothing
End Function

Remarks

This constructor sets the SpnLookupTime property to 1 minute.

SpnEndpointIdentity(String)

Initializes a new instance of SpnEndpointIdentity with the specified service principal name (SPN).

public:
 SpnEndpointIdentity(System::String ^ spnName);
public SpnEndpointIdentity (string spnName);
new System.ServiceModel.SpnEndpointIdentity : string -> System.ServiceModel.SpnEndpointIdentity
Public Sub New (spnName As String)

Parameters

spnName
String

The SPN.

Exceptions

spnName is null.

Examples

The following code shows how to create identities from a string representation of the SPN.

static EndpointIdentity CreateSpnIdentity()
{
    WindowsIdentity self = WindowsIdentity.GetCurrent();
    SecurityIdentifier sid = self.User;

    SpnEndpointIdentity identity = null;

    identity = new SpnEndpointIdentity(String.Format(CultureInfo.InvariantCulture, "host/{0}", GetMachineName()));

    return identity;
}
static string GetMachineName()
{
    return Dns.GetHostEntry(string.Empty).HostName;
}
Private Shared Function CreateSpnIdentity() As EndpointIdentity
    Dim self As WindowsIdentity = WindowsIdentity.GetCurrent()
    Dim sid As SecurityIdentifier = self.User

    Dim identity As SpnEndpointIdentity = Nothing

    identity = New SpnEndpointIdentity(String.Format(CultureInfo.InvariantCulture, "host/{0}", GetMachineName()))

    Return identity
End Function
Private Shared Function GetMachineName() As String
    Return Dns.GetHostEntry(String.Empty).HostName
End Function

Remarks

This constructor sets the SpnLookupTime property to 1 minute.

Applies to