다음을 통해 공유


EndpointIdentity.CreateUpnIdentity(String) 메서드

정의

지정된 이름으로 UPN(사용자 계정 이름) ID를 만듭니다.

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

매개 변수

upnName
String

UPN ID의 이름입니다.

반환

EndpointIdentity

지정된 EndpointIdentity과 연결된 UPN upnName입니다.

예외

upnName이(가) null인 경우

예제

다음 코드에서는 이 메서드를 호출하는 방법을 보여 줍니다.

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

설명

이 ID를 사용하여 엔드포인트에 연결하는 보안 WCF 클라이언트는 엔드포인트에서 SSPI 인증을 수행할 때 UPN을 사용합니다.

이 정적 메서드는 입력 매개 변수로 사용하여 생성자를 UpnEndpointIdentity호출하여 upnName 인스턴스 UpnEndpointIdentity 를 만듭니다.

빈 문자열로 지정된 경우 가능하면 upnName 인증이 Kerberos에서 NTLM으로 대체됩니다. 이 false경우 AllowNtlm WCF는 NTLM을 사용하는 경우 예외를 throw하기 위해 최선을 다합니다. 이 속성을 false로 설정하면 유선을 통해 NTLM 자격 증명을 보낼 수 있습니다.

적용 대상