Partage via


EndpointIdentity.CreateSpnIdentity(String) Méthode

Définition

Crée une identité SPN (server principal name) portant le nom spécifié.

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

Paramètres

spnName
String

Nom de l'identité SPN.

Retours

EndpointIdentity

EndpointIdentity SPN associée au spnName spécifié.

Exceptions

spnName a la valeur null.

Exemples

L'exemple de code suivant montre comment appeler cette méthode.

// 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();

Remarques

Un client WCF sécurisé qui se connecte à un point de terminaison avec cette identité utilise le SPN lors de l’exécution de l’authentification SSPI avec le point de terminaison.

Cette méthode statique crée une instance de SpnEndpointIdentity en appelant son constructeur, SpnEndpointIdentity, en utilisant spnName en guise de paramètre d'entrée.

Si le spnName est spécifié avec une chaîne vide, l'authentification bascule de Kerberos vers NTLM, lorsque c'est possible. Si AllowNtlm a la valeur false, l'authentification échoue.

S’applique à