コード例 #1
0
ファイル: Program.cs プロジェクト: VladimirDimov/WebServices
        static void Main()
        {
            var serviceAddress = new Uri("http://localhost:56599/StringCounterService.svc");
            ServiceHost selfHost = new ServiceHost(
                typeof(StringCounterService), serviceAddress);

            var smb = new ServiceMetadataBehavior();
            smb.HttpGetEnabled = true;
            selfHost.Description.Behaviors.Add(smb);

            selfHost.Open();
            Console.WriteLine("Running at " + serviceAddress);

            StringCounterServiceClient client = new StringCounterServiceClient();

            using (client)
            {
                var text = "asd asd asd qeqwrqwr asdasd";
                var requestedString = "asd";
                var result = client.Count(text, requestedString);
                Console.WriteLine("Text: {0}; Requested string: {1}; Result: {2}", text, requestedString, result);
            }

            Console.WriteLine("Press enter to exit");
            Console.ReadLine();
        }
コード例 #2
0
        private static void Main()
        {
            Helper.ConsoleMio.Setup();

            Helper.ConsoleMio.PrintHeading("Substring Counting Service, You've come to the right place");

            var service = new StringCounterServiceClient();

            do
            {
                string pattern = Helper.ConsoleMio.Write("Enter the first string: ", ConsoleColor.DarkCyan)
                .ReadInColor(ConsoleColor.Blue);

                string mainString = Helper.ConsoleMio.Write("Enter the second string: ", ConsoleColor.DarkCyan)
                    .ReadInColor(ConsoleColor.Blue);

                int result = service.CountSubstringOccurence(pattern, mainString);

                Helper.ConsoleMio
                    .Write("'{0}'", ConsoleColor.DarkBlue, mainString)
                    .Write(" contains ", ConsoleColor.DarkCyan)
                    .Write("'{0}'", ConsoleColor.DarkRed, pattern)
                    .WriteLine(" {0} time{1}", ConsoleColor.Blue, result, result == 1 ? string.Empty : "s")
                    .WriteLine("\nPress 'Esc' to exit or other key to repeat...\n", ConsoleColor.DarkGray);
            } while (Console.ReadKey(true).Key != ConsoleKey.Escape);

            service.Close();

            Environment.Exit(0);
        }