EndpointIdentity.CreateUpnIdentity(String) Método

Definición

Crea una identidad de nombre principal de usuario (UPN) con un nombre especificado.Creates a user principal name (UPN) identity with a specified name.

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

Parámetros

upnName
String

Nombre para la identidad UPN.The name for the UPN identity.

Devoluciones

EndpointIdentity

UPN EndpointIdentity asociado al upnName especificado.A UPN EndpointIdentity associated with the specified upnName.

Excepciones

upnName es null.upnName is null.

Ejemplos

El siguiente código muestra cómo llamar a este método.The following code shows how to call this method.

namespace TestPrincipalPermission
{
    class PrincipalPermissionModeWindows
    {

        [ServiceContract]
        interface ISecureService
        {
            [OperationContract]
            string Method1();
        }

        class SecureService : ISecureService
        {
            [PrincipalPermission(SecurityAction.Demand, Role = "everyone")]
            public string Method1()
            {
                return String.Format("Hello, \"{0}\"", Thread.CurrentPrincipal.Identity.Name);
            }
        }

        public void Run()
        {
            Uri serviceUri = new Uri(@"http://localhost:8006/Service");
            ServiceHost service = new ServiceHost(typeof(SecureService));
            service.AddServiceEndpoint(typeof(ISecureService), GetBinding(), serviceUri);
            service.Authorization.PrincipalPermissionMode = PrincipalPermissionMode.UseAspNetRoles;
            service.Open();

            EndpointAddress sr = new EndpointAddress(
                serviceUri, EndpointIdentity.CreateUpnIdentity(WindowsIdentity.GetCurrent().Name));
            ChannelFactory<ISecureService> cf = new ChannelFactory<ISecureService>(GetBinding(), sr);
            ISecureService client = cf.CreateChannel();
            Console.WriteLine("Client received response from Method1: {0}", client.Method1());
            ((IChannel)client).Close();
            Console.ReadLine();
            service.Close();
        }

        public static Binding GetBinding()
        {
            WSHttpBinding binding = new WSHttpBinding(SecurityMode.Message);
            binding.Security.Message.ClientCredentialType = MessageCredentialType.Windows;
            return binding;
        }
    }
}

Comentarios

Un cliente WCF seguro que se conecta a un punto de conexión con esta identidad utiliza el UPN al realizar la autenticación SSPI con el punto de conexión.A secure WCF client that connects to an endpoint with this identity uses the UPN when performing SSPI authentication with the endpoint.

Este método estático crea una instancia de UpnEndpointIdentity llamando a su constructor, UpnEndpointIdentity, utilizando upnName como parámetro de entrada.This static method creates an instance of UpnEndpointIdentity by calling its constructor, UpnEndpointIdentity, using upnName as the input parameter.

Si upnName se especifica con una cadena vacía, la autenticación se retirará de Kerberos a NTLM si es posible.If upnName is specified with an empty string, authentication falls back from Kerberos to NTLM if possible. Si AllowNtlm es false , WCF realiza el mejor esfuerzo para iniciar una excepción si se usa NTLM.If AllowNtlm is false, WCF makes a best-effort to throw an exception if NTLM is used. Tenga en cuenta que, aunque se establezca esta propiedad en false, es posible que se envíen igualmente las credenciales NTLM a través de la conexión.Note that setting this property to false may not prevent NTLM credentials from being sent over the wire.

Se aplica a