Ejemplo n.º 1
0
        private static void RunSync()
        {
            ClientBase <IPollingSession> .CacheSetting = CacheSetting.AlwaysOn;
            DuplexChannelFactory <IPollingSession> factory = new DuplexChannelFactory <IPollingSession>(typeof(ClientContract), "server");
            List <IPollingSession> clients = new List <IPollingSession>();

            //Subscribe.
            Console.WriteLine("Press ENTER to subscribe and shut down client");
            Console.ReadLine();
            Console.WriteLine("Subscribing");
            for (int i = 0; i < clientCount; i++)
            {
                //if ((i % 100) == 0)
                //{
                //	factory = new DuplexChannelFactory<ISampleContract>(typeof(ClientContract), "server");
                //}
                IPollingSession client = factory.CreateChannel(new InstanceContext(new ClientContract()));
                client.Subscribe();
                clients.Add(client);
                //Console.WriteLine(i+1);
            }

            Console.WriteLine();
            Console.WriteLine("Press ENTER to unsubscribe and shut down client");
            Console.ReadLine();

            Console.WriteLine("Unsubscribing");
            for (int i = 0; i < clientCount; i++)
            {
                IPollingSession client = clients[i];
                client.Unsubscribe();
                //Closing the client gracefully closes the connection and cleans up resources
                ((IChannel)client).Close();
            }
        }
Ejemplo n.º 2
0
        private static void RunOneInstance()
        {
            ClientBase <IPollingSession> .CacheSetting = CacheSetting.AlwaysOn;
            DuplexChannelFactory <IPollingSession> factory = new DuplexChannelFactory <IPollingSession>(typeof(ClientContract), "server");

            Console.WriteLine("Press ENTER to subscribe");
            Console.ReadLine();
            Console.WriteLine("Subscribing");

            IPollingSession client  = factory.CreateChannel(new InstanceContext(new ClientContract()));
            IChannel        channel = (IChannel)client;

            channel.Open();
            channel.Closed  += channel_Closed;
            channel.Faulted += channel_Faulted;
            client.Subscribe();
            Console.WriteLine("Subscribed");
            Console.WriteLine("Press ENTER to unsubscribe");
            Console.ReadLine();

            client.Unsubscribe();
            Console.WriteLine("Unsubscribed");
            Console.WriteLine("Press ENTER to close channel");
            Console.ReadLine();

            channel.Close();
            Console.WriteLine("Channel closed");
            Console.WriteLine("Press ENTER to exit");
            Console.ReadLine();
        }