服务器已拒绝客户端凭据Windows身份验证.NET

时间:2018-11-07 15:28:11

标签: authentication tcp windows-authentication

我在两台不同的计算机上安装了客户端和服务器控制台应用程序。当我尝试连接时,出现错误“服务器已拒绝客户端凭据”。 我在服务器端的代码是:

 NetTcpBinding bindingForUser = new NetTcpBinding();
        bindingForUser.Security.Mode = SecurityMode.Transport;
        bindingForUser.Security.Transport.ProtectionLevel = System.Net.Security.ProtectionLevel.EncryptAndSign;
        bindingForUser.Security.Transport.ClientCredentialType = TcpClientCredentialType.Windows;
        bindingForUser.Security.Message.ClientCredentialType = MessageCredentialType.Windows;

        string addressForUser = "net.tcp://localhost:10001/AuthenticationService";

        ServiceHost host = new ServiceHost(typeof(AuthenticationService));
        host.AddServiceEndpoint(typeof(IAuthenticationService), bindingForUser, addressForUser);
        host.Description.Behaviors.Remove(typeof(ServiceDebugBehavior));
        host.Description.Behaviors.Add(new ServiceDebugBehavior() { IncludeExceptionDetailInFaults = true });    host.open

在客户端上,我有:

NetTcpBinding binding = new NetTcpBinding();
        binding.Security.Mode = SecurityMode.Transport;
        binding.Security.Transport.ProtectionLevel = System.Net.Security.ProtectionLevel.EncryptAndSign;
        binding.Security.Transport.ClientCredentialType = TcpClientCredentialType.Windows;
        string address = "net.tcp://localhost:10001/AuthenticationService";
        string username, password;
        bool loggedIn = false;
        Console.WriteLine("************************* Welcome to user terminal *************************");

        using (AccountUserProxy proxy = new AccountUserProxy(binding, address))
        {
            while (!loggedIn)
            {
                Console.WriteLine("Please enter your username >> ");
                username = Console.ReadLine();
                Console.WriteLine("Please enter your password >> ");
                password = Console.ReadLine();
                loggedIn = proxy.Login(username,password);
            }

            Console.WriteLine("Press any key to log out >> ");
            Console.ReadLine();
            proxy.LogOut();
        }

IAuthenticationService factory;

    public AccountUserProxy(NetTcpBinding binding, string address) : base(binding, address)
    {
        factory = this.CreateChannel();
    }

有人可以看到问题吗?

0 个答案:

没有答案
相关问题