Share via


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 に関連付けられた UPN upnName

例外

upnNamenullです。

このメソッドを呼び出す方法を次のコードに示します。

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 を呼び出し、UpnEndpointIdentity を入力パラメーターとして使用することで、upnName のインスタンスを作成します。

upnName が空の文字列で指定される場合、認証は、可能であれば Kerberos の代わりに NTLM を使用します。 が のfalse場合AllowNtlm、NTLM が使用されている場合、WCF は例外をスローするベスト エフォートを行います。 ただし、このプロパティを false に設定しても、ネットワーク経由で NTLM 資格情報が送信されなくなるとは限りません。

適用対象