Freigeben über


EndpointIdentity.CreateSpnIdentity(String) Methode

Definition

Erstellt eine Serverprinzipalname(SPN)-Identität mit einem angegebenen Namen.

public:
 static System::ServiceModel::EndpointIdentity ^ CreateSpnIdentity(System::String ^ spnName);
public static System.ServiceModel.EndpointIdentity CreateSpnIdentity(string spnName);
static member CreateSpnIdentity : string -> System.ServiceModel.EndpointIdentity
Public Shared Function CreateSpnIdentity (spnName As String) As EndpointIdentity

Parameter

spnName
String

Der Name für die SPN-Identität.

Gibt zurück

Ein SPN EndpointIdentity , der dem angegebenen zugeordnet spnNameist.

Ausnahmen

spnName ist null.

Beispiele

Der folgende Code zeigt, wie diese Methode aufgerufen wird.

// Create the service host.
ServiceHost myServiceHost = new ServiceHost(typeof(Calculator));

// Create the binding.
WSHttpBinding binding = new WSHttpBinding();
binding.Security.Mode = SecurityMode.Message;
binding.Security.Message.ClientCredentialType =
     MessageCredentialType.Windows;

// Disable credential negotiation and establishment of the
// security context.
binding.Security.Message.NegotiateServiceCredential = false;
binding.Security.Message.EstablishSecurityContext = false;

// Create a URI for the endpoint address.
Uri httpUri = new Uri("http://localhost/Calculator");

// Create the EndpointAddress with the SPN for the Identity.
EndpointAddress ea = new EndpointAddress(httpUri,
    EndpointIdentity.CreateSpnIdentity("service_spn_name"));

// Get the contract from the ICalculator interface (not shown here).
// See the sample applications for an example of the ICalculator.
ContractDescription contract = ContractDescription.GetContract(
    typeof(ICalculator));

// Create a new ServiceEndpoint.
ServiceEndpoint se = new ServiceEndpoint(contract, binding, ea);

// Add the service endpoint to the service.
myServiceHost.Description.Endpoints.Add(se);

// Open the service.
myServiceHost.Open();
Console.WriteLine("Listening...");
Console.ReadLine();

// Close the service.
myServiceHost.Close();

Hinweise

Ein sicherer WCF-Client, der eine Verbindung mit einem Endpunkt mit dieser Identität herstellt, verwendet den SPN beim Ausführen der SSPI-Authentifizierung mit dem Endpunkt.

Diese statische Methode erstellt eine Instanz des Aufrufs des Konstruktors mithilfe des Eingabeparameters.This static method creates an instance of SpnEndpointIdentity by calling its constructor, SpnEndpointIdentityusing spnName as the input parameter.

Wenn spnName mit einer leeren Zeichenfolge angegeben wird, wird die Authentifizierung nach Möglichkeit von Kerberos auf NTLM zurückfallen. Ist AllowNtlm dies falseder Fehler , schlägt die Authentifizierung fehl.

Gilt für: