Example #1
0
        static void Main(string[] args)
        {
            const string serviceCertCN = "wcfservice";

            Console.WriteLine(args.Length);

            var binding = new NetTcpBinding();

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

            var serviceCertificate = CertManager.GetCertificateFromStorage(StoreName.My, StoreLocation.LocalMachine, serviceCertCN);

            var address  = "net.tcp://localhost:9998/LBDuplexWorker";
            var endpoint = new EndpointAddress(new Uri(address), new X509CertificateEndpointIdentity(serviceCertificate));
            var handler  = new CallBackHandler();

            using (var proxy = new LBDuplexClient(handler, binding, endpoint))
            {
                proxy.Subscribe();
                Console.WriteLine("Subscribed to LoadBalancer.");

                var timer = new Timer
                {
                    /// timer interval is extracted from command line argument.
                    Interval = double.Parse(args[1])
                               //Interval = 10000
                };

                timer.Elapsed += delegate { OnTimedEvent(proxy); };
                timer.Start();

                Console.ReadKey(false);
            }
        }
Example #2
0
        public LBDuplexClient(CallBackHandler handler, NetTcpBinding binding, EndpointAddress address)
            : base(new InstanceContext(handler), binding, address)
        {
            //logger = new Logger("LB.Audit", "LoadBalancerLog");
            string clientCertCN = Formatter.ParseName(WindowsIdentity.GetCurrent().Name);

            this.Credentials.ServiceCertificate.Authentication.CertificateValidationMode = X509CertificateValidationMode.ChainTrust;
            this.Credentials.ServiceCertificate.Authentication.RevocationMode            = X509RevocationMode.NoCheck;
            this.Credentials.ClientCertificate.Certificate = CertManager.GetCertificateFromStorage(StoreName.My, StoreLocation.LocalMachine, clientCertCN);

            proxy = this.CreateChannel();
        }