Esempio n. 1
0
        /// <summary>
        /// Adds a new person to phone book.
        /// </summary>
        /// <param name="recordToAdd">Person informations to add</param>
        public void AddPerson(PhoneBookRecord recordToAdd)
        {
            if (recordToAdd == null)
            {
                throw new ArgumentNullException("recordToAdd");
            }

            _records[recordToAdd.Name] = recordToAdd;
            Console.WriteLine("A new person is added: "+ recordToAdd.Name + " (" + recordToAdd.Phone + ")");
        }
Esempio n. 2
0
        static void Main()
        {
            //Create a client to connecto to phone book service on local server and 10048 TCP port.
            var client = ScsServiceClientBuilder.CreateClient<IPhoneBookService>(
                new ScsTcpEndPoint("127.0.0.1", 10048));

            Console.WriteLine("Press enter to connect to phone book service...");
            Console.ReadLine();

            //Connect to the server
            client.Connect();

            var person1 = new PhoneBookRecord { Name = "Halil ibrahim", Phone = "5881112233" };
            var person2 = new PhoneBookRecord { Name = "John Nash", Phone = "58833322211" };

            //Add some persons
            client.ServiceProxy.AddPerson(person1);
            client.ServiceProxy.AddPerson(person2);

            //Search for a person
            var person = client.ServiceProxy.FindPerson("Halil");
            if (person != null)
            {
                Console.WriteLine("Person is found:");
                Console.WriteLine(person);
            }
            else
            {
                Console.WriteLine("Can not find person!");
            }

            Console.WriteLine();
            Console.WriteLine("Press enter to disconnect from phone book service...");
            Console.ReadLine();

            //Disconnect from server
            client.Disconnect();
        }