Пример #1
0
        internal static List <IDisconnectCallback> myClients = new List <IDisconnectCallback>(); //list of servers clients
        static void Main(string[] args)
        {
            //connect to CMS on start-up
            try
            {
                EventLogManager.InitializeServerEventLog();

                cmsClient = ConnectToCMS();
                if (cmsClient == null)
                {
                    throw new Exception("Connection with CMS not established");
                }

                Console.WriteLine("*Successfully connected to CMS*");
                Prompt();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {
                cmsClient.Close();
            }

            Console.WriteLine("\n> Press enter to close program");
            Console.ReadLine();
        }
Пример #2
0
        private static CMSClient ConnectToCMS()
        {
            try
            {
                NetTcpBinding binding = new NetTcpBinding();
                InitializeWindowsAuthentication(binding);
                EndpointAddress address          = new EndpointAddress(new Uri(ConfigurationSettings.AppSettings.Get("CMSProxy")));
                var             callbackInstance = new ServerCallback();

                CMSClient proxy = new CMSClient(callbackInstance, binding, address);
                proxy.RegisterClient();

                return(proxy);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                return(null);
            }
        }
        static void Main(string[] args)
        {
            Console.ReadKey();

            NetTcpBinding   binding2 = new NetTcpBinding();
            EndpointAddress address2 = new EndpointAddress("net.tcp://localhost:1324/CMS");

            using (CMSClient proxy2 = new CMSClient(binding2, address2))
            {
                bool             temp = false;
                X509Certificate2 serverCertificate = null;

                string tempCertificate = WindowsIdentity.GetCurrent().Name;

                string[] parse = tempCertificate.Split('\\');

                string serverCertificateName = parse[1];

                serverCertificate = ServerGet.GetCertificateFromStorage(StoreName.My, StoreLocation.LocalMachine, serverCertificateName);
                if (serverCertificate == null)
                {
                    Console.WriteLine("Enter new certificate password: "******"Postoji sertifikat.");
                }

                NetTcpBinding binding = new NetTcpBinding();

                binding.Security.Transport.ClientCredentialType = TcpClientCredentialType.Certificate;

                string address = "net.tcp://localhost:1234/Server";

                ServiceHost host = new ServiceHost(typeof(WCFService));

                host.AddServiceEndpoint(typeof(IWCFContract), binding, address);

                host.Credentials.ClientCertificate.Authentication.CertificateValidationMode = X509CertificateValidationMode.Custom;

                host.Credentials.ClientCertificate.Authentication.CustomCertificateValidator = new ServiceCustomValidator(proxy2);

                host.Credentials.ClientCertificate.Authentication.RevocationMode = X509RevocationMode.NoCheck;

                host.Credentials.ServiceCertificate.Certificate = serverCertificate;

                Task task = new Task(() => LoggedBase.CheckIsAlive());
                task.Start();

                try
                {
                    Thread.Sleep(5000);
                    host.Open();
                    Console.WriteLine("WCFService is started.\nPress <enter> to stop ...");

                    Console.ReadLine();
                }
                catch (Exception e)
                {
                    Console.WriteLine("[ERROR] {0}", e.Message);
                    Console.WriteLine("[StackTrace] {0}", e.StackTrace);
                    Console.ReadLine();
                }
                finally
                {
                    host.Close();
                }
                Console.ReadLine();
            }
        }
 public ServiceCustomValidator(CMSClient p)
 {
     proxy = p;
 }