Beispiel #1
0
        public Subscriber(NetTcpBinding binding, EndpointAddress address, MyServiceCallback callback) : base(callback, binding, address)
        {
            string cltCertCN = Formatter.ParseName(WindowsIdentity.GetCurrent().Name);

            Credentials.ServiceCertificate.Authentication.CertificateValidationMode  = System.ServiceModel.Security.X509CertificateValidationMode.Custom;
            Credentials.ServiceCertificate.Authentication.CustomCertificateValidator = new ClientCertValidator();
            Credentials.ServiceCertificate.Authentication.RevocationMode             = X509RevocationMode.NoCheck;
            Credentials.ClientCertificate.Certificate = CertManager.GetCertificateFromStorage(StoreName.My, StoreLocation.LocalMachine, cltCertCN);

            factory = CreateChannel();
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            string srvCertCN = "PubSubEngine";

            MyAuditBehavior myAuditBehavior = new MyAuditBehavior();

            NetTcpBinding binding = new NetTcpBinding();

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

            X509Certificate2 srvCert = CertManager.GetCertificateFromStorage(StoreName.TrustedPeople, StoreLocation.LocalMachine, srvCertCN);

            EndpointAddress address = new EndpointAddress(new Uri("net.tcp://localhost:8888/Subscriber"), new X509CertificateEndpointIdentity(srvCert));

            MyServiceCallback subscriberCallback = new MyServiceCallback();
            InstanceContext   instanceContext    = new InstanceContext(subscriberCallback);

            string subject, from, to;

            using (Subscriber proxy = new Subscriber(binding, address, subscriberCallback))
            {
                Console.WriteLine("Connected to the PubSubEngine\n");

                while (true)
                {
                    proxy.RegisterSubscriber();
                    PrintMenu();
                    int choice = int.Parse(Console.ReadLine());

                    switch (choice)
                    {
                    case 1:
                        if (proxy.UnregisterSubscriber())
                        {
                            Console.WriteLine("Successfully unregistered.");
                        }
                        else
                        {
                            Console.WriteLine("Failed to unregister.");
                        }
                        break;

                    case 2:
                        Console.Write("Enter topic name: ");
                        subject = Console.ReadLine();
                        Console.Write("Enter risk range: \nfrom: ");
                        from = Console.ReadLine();
                        Console.Write("to: ");
                        to = Console.ReadLine();
                        if (proxy.Subscribe(subject, Int32.Parse(from), Int32.Parse(to)))
                        {
                            Console.WriteLine("Successfully subscribed.");
                        }
                        else
                        {
                            Console.WriteLine("Unable to subscribe");
                        }
                        break;

                    case 3:
                        Console.Write("Enter topic name: ");
                        if (proxy.Unsubsrcibe(Console.ReadLine()))
                        {
                            Console.WriteLine("Successfully unsubscribed.");
                        }
                        else
                        {
                            Console.WriteLine("Unable to unsubscribe.");
                        }
                        break;

                    default:
                        Console.WriteLine("Bad input, try again.");
                        break;
                    }

                    if (choice == 1)
                    {
                        break;
                    }
                }
            }
        }