EndpointIdentity.CreateUpnIdentity(String) Metod

Definition

Skapar en UPN-identitet (user principal name) med ett angivet namn.

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

Parametrar

upnName
String

Namnet på UPN-identiteten.

Returer

Ett UPN EndpointIdentity som är associerat med angivet upnName.

Undantag

upnName är null.

Exempel

Följande kod visar hur du anropar den här metoden.

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;
        }
    }
}

Kommentarer

En säker WCF-klient som ansluter till en slutpunkt med den här identiteten använder UPN när du utför SSPI-autentisering med slutpunkten.

Den här statiska metoden skapar en instans av genom att anropa konstruktorn, UpnEndpointIdentity, med hjälp UpnEndpointIdentity av upnName som indataparameter.

Om upnName anges med en tom sträng återgår autentiseringen från Kerberos till NTLM om möjligt. I AllowNtlmfalsefall gör WCF ett bästa försök att utlösa ett undantag om NTLM används. Observera att inställningen för den här egenskapen false kanske inte hindrar NTLM-autentiseringsuppgifter från att skickas via kabeln.

Gäller för