Exemplo n.º 1
0
        /// <summary>
        /// you only need to run this host, and will have access to the service via console interface.
        /// no need to first start the servcelibrary before running this project, because this is a host,
        /// not a client (which is a consumer and needs to have an upp and running servcie somewhere so taht
        /// the client can consume it).
        /// </summary>
        /// <param name="args"></param>
        static void Main(string[] args)
        {
            ServiceHost host = new ServiceHost(typeof(EvalService));

            // CONFIGURATION in program instead off in the app.config
            //host.AddServiceEndpoint(typeof(IEvalService), new BasicHttpBinding(), "Http://localhost:8080/evals/basic");

            try
            {
                host.Open();

                EvalService service = new EvalService();

                Eval eone = new Eval();
                eone.Submitter = "ivan prgomet";
                eone.Comments  = "really cool | sweet | neat";
                eone.TimeSent  = DateTime.Now;

                service.SubmitEval(eone);
                List <Eval> evals = service.GetEvals();

                PrintEvals(evals);

                host.Close();
            }
            catch (Exception)
            {
                host.Abort();
                throw;
            }
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            ServiceHost host = new ServiceHost(typeof(EvalService));

            //configure host before opening
            host.AddServiceEndpoint(typeof(IEvalService), new BasicHttpBinding(), "Http://localhost:8080/evals/basic");
            host.AddServiceEndpoint(typeof(IEvalService), new WSHttpBinding(), "Http://localhost:8080/evals/ws");
            host.AddServiceEndpoint(typeof(IEvalService), new NetTcpBinding(), "net.tcp://localhost:8081/evals");

            try
            {
                host.Open();
                #region service info
                Console.WriteLine($"{host.Description.ServiceType} is up and running with these endpoints:\n");
                foreach (ServiceEndpoint se in host.Description.Endpoints)
                {
                    Console.WriteLine(se.Address);
                }
                Console.WriteLine();
                #endregion

                EvalService evalService = new EvalService();

                Eval eval = new Eval()
                {
                    Submitter = "ivan prgomet",
                    TimeSent  = DateTime.Now,
                    Comments  = "Hello World",
                };
                Eval eval2 = new Eval()
                {
                    Submitter = "jon jonsson",
                    TimeSent  = DateTime.Now,
                    Comments  = "Hello Universe",
                };

                evalService.SubmitEval(eval);
                evalService.SubmitEval(eval2);


                List <Eval> myEvals = evalService.GetEvals();

                foreach (var e in myEvals)
                {
                    Console.WriteLine("Submitter: " + e.Submitter);
                    Console.WriteLine("Comment: " + e.Comments);
                    Console.WriteLine("TimeSent: " + e.TimeSent + "\n");
                }

                host.Close();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                host.Abort();
            }
        }
Exemplo n.º 3
0
        static void Main(string[] args)
        {
            var host = new ServiceHost(typeof(EvalService));

            host.AddServiceEndpoint(typeof(IEvalService), new BasicHttpBinding(), "http://localhost:8080/Evals/basic");
            host.AddServiceEndpoint(typeof(IEvalService), new WSHttpBinding(), "http://localhost:8080/Evals/ws");
            host.AddServiceEndpoint(typeof(IEvalService), new NetTcpBinding(), "net.tcp://localhost:8081/Evals/");



            try
            {
                host.Open();
                PrintServiceInfo(host);
                var evalService = new EvalService();
                var eval        = new Eval()
                {
                    Submitter = "Chuck Norris",
                    TimeSent  = DateTime.Now,
                    Comment   = "It Works!"
                };
                evalService.SubmitEval(eval);
                var evalList = new List <Eval>();
                evalList = evalService.GetEvals();
                if (evalList != null)
                {
                    foreach (var e in evalList)
                    {
                        Console.WriteLine("Submitted Evaluations");
                        Console.WriteLine("---------------------------------------------");
                        Console.WriteLine($"Submitter: {e.Submitter} Time: {e.TimeSent}");
                        Console.WriteLine($"Comment: {e.Comment}");
                        Console.WriteLine("---------------------------------------------");
                    }
                }
                host.Close();
            }
            catch (Exception e)
            {
                Console.Write(e.Message);
                host.Abort();
            }
            Console.ReadLine();
        }
Exemplo n.º 4
0
        static void Main(string[] args)
        {
            ServiceHost host = new ServiceHost(typeof(EvalService));

            TimeSpan timeout = new TimeSpan(0, 0, 2);

            host.AddServiceEndpoint(typeof(IEvalService), new BasicHttpBinding {
                SendTimeout = timeout
            }, "http://localhost:8080/evals/basic");
            host.AddServiceEndpoint(typeof(IEvalService), new WSHttpBinding(), "http://localhost:8080/evals/ws");
            host.AddServiceEndpoint(typeof(IEvalService), new NetTcpBinding(), "net.tcp://localhost:8088/evals");


            try
            {
                host.Open();

                EvalService evalService = new EvalService();
                Eval        eval        = new Eval {
                    Comments  = "Kommentar",
                    Submitter = "Submitter",
                    Timesent  = DateTime.Now
                };

                evalService.SubmitEval(eval);
                List <Eval> evals = evalService.GetEvals();

                foreach (Eval item in evals)
                {
                    Console.WriteLine($"{item.Submitter} {item.Comments} {item.Timesent}");
                }

                Console.ReadKey();
                host.Close();
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                Console.ReadKey();
                host.Abort();
            }
        }