Esempio n. 1
0
        static void WorkViaGeneratedProxy()
        {
            Console.WriteLine("Retrieving endpoints vis MEX...");
            ServiceEndpointCollection endpoints =
                MetadataResolver.Resolve(typeof(IEvalService),
                                         new EndpointAddress("http://localhost:8080/evals/mex"));

            Console.WriteLine("Endpoints retrieved");

            foreach (var endpoint in endpoints)
            {
                Console.WriteLine(endpoint.Address.Uri);
                var client = new EvalServiceClient(endpoint.Binding, endpoint.Address);
                try
                {
                    WorkWithService(client);
                    client.Close();
                }
                catch (FaultException fe)
                {
                    Console.WriteLine($"Fault exception: {fe.GetType()}");
                    client.Abort();
                }
                catch (CommunicationException ce)
                {
                    Console.WriteLine($"Communication exception: {ce.GetType()}");
                    client.Abort();
                }
                catch (TimeoutException te)
                {
                    Console.WriteLine($"Timeout exception: {te.GetType()}");
                    client.Abort();
                }
            }
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            #region example using ChannelFactory<T> directly
            //ChannelFactory<IEvalService> cf =
            //    new ChannelFactory<IEvalService>("WSHttpBinding_IEvalService");
            //IEvalService channel = cf.CreateChannel();
            #endregion

            Console.WriteLine("Retrieving endpoints via MEX...");

            ServiceEndpointCollection endpoints =
                MetadataResolver.Resolve(typeof(IEvalService),
                    new EndpointAddress("http://localhost:8080/evals/mex"));

            foreach (ServiceEndpoint se in endpoints)
            {
                EvalServiceClient channel =
                    new EvalServiceClient(se.Binding, se.Address);

                try
                {
                    EvalServiceLibrary.Eval eval =
                        new EvalServiceLibrary.Eval("Aaron", "I'm really liking this");
                    channel.SubmitEval(eval);
                    channel.SubmitEval(eval);

                    List<EvalServiceLibrary.Eval> evals = channel.GetEvals();
                    Console.WriteLine("Number of evals: {0}", evals.Count);

                    #region async example
                    //channel.GetEvalsCompleted += new EventHandler<GetEvalsCompletedEventArgs>(channel_GetEvalsCompleted);
                    //channel.GetEvalsAsync();
                    //Console.WriteLine("Waiting...");
                    //Console.ReadLine();
                    #endregion

                    channel.Close();
                }
                catch (FaultException fe)
                {
                    Console.WriteLine("FaultException handler: {0}",
                        fe.GetType());
                    channel.Abort();
                }
                catch (CommunicationException ce)
                {
                    Console.WriteLine("CommunicationException handler: {0}",
                        ce.GetType());
                    channel.Abort();
                }
                catch (TimeoutException te)
                {
                    Console.WriteLine("TimeoutException handler: {0}",
                        te.GetType());
                    channel.Abort();
                }
            }
        }
Esempio n. 3
0
        static void Main(string[] args)
        {
            #region example using ChannelFactory<T> directly
            //ChannelFactory<IEvalService> cf =
            //    new ChannelFactory<IEvalService>("WSHttpBinding_IEvalService");
            //IEvalService channel = cf.CreateChannel();
            #endregion

            Console.WriteLine("Retrieving endpoints via MEX...");

            ServiceEndpointCollection endpoints =
                MetadataResolver.Resolve(typeof(IEvalService),
                                         new EndpointAddress("http://localhost:8080/evals/mex"));

            foreach (ServiceEndpoint se in endpoints)
            {
                EvalServiceClient channel =
                    new EvalServiceClient(se.Binding, se.Address);

                try
                {
                    EvalServiceLibrary.Eval eval =
                        new EvalServiceLibrary.Eval("Aaron", "I'm really liking this");
                    channel.SubmitEval(eval);
                    channel.SubmitEval(eval);

                    List <EvalServiceLibrary.Eval> evals = channel.GetEvals();
                    Console.WriteLine("Number of evals: {0}", evals.Count);

                    #region async example
                    //channel.GetEvalsCompleted += new EventHandler<GetEvalsCompletedEventArgs>(channel_GetEvalsCompleted);
                    //channel.GetEvalsAsync();
                    //Console.WriteLine("Waiting...");
                    //Console.ReadLine();
                    #endregion

                    channel.Close();
                }
                catch (FaultException fe)
                {
                    Console.WriteLine("FaultException handler: {0}",
                                      fe.GetType());
                    channel.Abort();
                }
                catch (CommunicationException ce)
                {
                    Console.WriteLine("CommunicationException handler: {0}",
                                      ce.GetType());
                    channel.Abort();
                }
                catch (TimeoutException te)
                {
                    Console.WriteLine("TimeoutException handler: {0}",
                                      te.GetType());
                    channel.Abort();
                }
            }
        }
Esempio n. 4
0
        public static void Main(string[] args)
        {
            // var cf = new ChannelFactory<IEvalServiceChannel>("NetNamedPipeBinding_IEvalService");
            // var channel = cf.CreateChannel();
            var endpoints = MetadataResolver.Resolve(
                typeof(IEvalService),
                new EndpointAddress("http://localhost:8080/evals/mex"));

            foreach (var se in endpoints)
            {
                var channel = new EvalServiceClient(se.Binding, se.Address);

                // var channel = new EvalServiceClient("WSHttpBinding_IEvalService");
                try
                {
                    var eval = new Eval();
                    eval.Submitter = "Howard";
                    eval.Timesent  = DateTime.Now;
                    eval.Comments  = "I'm thinking this...";

                    channel.SubmitEval(eval);
                    channel.SubmitEval(eval);
                    var evals = channel.GetEvals();
                    Console.WriteLine("Number of evals: {0}", evals.Count);
                    channel.Close();
                }
                catch (FaultException fe)
                {
                    Console.WriteLine("FaultException handler: {0}", fe.GetType());
                    channel.Abort();
                }
                catch (CommunicationException ce)
                {
                    Console.WriteLine("CommunicationException handler: {0}", ce.GetType());
                    channel.Abort();
                }
                catch (TimeoutException te)
                {
                    Console.WriteLine("TimeoutException handler: {0}", te.GetType());
                    channel.Abort();
                }
            }

            Console.ReadLine();
        }
Esempio n. 5
0
        static void Main(string[] args)
        {
            Console.WriteLine("Enter Command to Execute Submit/Get, <Exit> to exit");
            string command = Console.ReadLine();

            if (command.Equals("Exit"))
            {
                goto close;
            }
            //EvalServiceClient evalServiceClient = new EvalServiceClient("BasicHttpBinding_IEvalService");
            EvalServiceClient evalServiceClient = new EvalServiceClient("NetTcpBinding_IEvalService");

            while (!command.Equals("Exit"))
            {
                try
                {
                    switch (command.ToLower())
                    {
                    case "submit":
                        Console.WriteLine("Enter Submitter");
                        string submitter = Console.ReadLine();
                        Console.WriteLine("Enter Comments");
                        string comments = Console.ReadLine();
                        Submit(evalServiceClient, submitter, comments);
                        break;

                    case "get":
                        GetAll(evalServiceClient);
                        break;

                    default:
                        Console.WriteLine("Incorrect input Enter Submit/Get");
                        break;
                    }
                }
                catch (FaultException <BadEvalSubmission> bad)
                {
                    Console.WriteLine("FaultException<BadEvalSubmission> is called");
                    Console.WriteLine(bad.Message);
                }
                catch (FaultException e)
                {
                    Console.WriteLine("FaultException handler is called");
                    Console.WriteLine(e.Message);
                }
                catch (CommunicationException ce)
                {
                    Console.WriteLine("CommunicationException handler is called");
                    Console.WriteLine(ce.Message);
                }
                catch (TimeoutException te)
                {
                    Console.WriteLine("Timeout handler is called");
                    Console.WriteLine(te.Message);
                }
                catch (Exception e)
                {
                    Console.WriteLine("General Exception is called");
                    Console.WriteLine(e.Message);
                }
                finally {
                    if (evalServiceClient.State == CommunicationState.Faulted)
                    {
                        Console.WriteLine("Clinet Channel has faulted...Creating new channel");
                    }
                    evalServiceClient.Abort();
                    evalServiceClient = new EvalServiceClient("NetTcpBinding_IEvalService");
                }
                Console.WriteLine("\n Enter Command to Execute Submit/Get, <Exit> to exit");
                if (command.Equals("Exit"))
                {
                    goto close;
                }
                command = Console.ReadLine();
            }
            Console.ReadLine();
            close : Console.WriteLine(".........");
        }
Esempio n. 6
0
        static void Main(string[] args)
        {
            // create a factory
            ///////////////////////////////////////////////////

            // factory by name
            ChannelFactory<IEvalService> factory1 = new ChannelFactory<IEvalService>("BasicHttpBinding_IEvalService");

            // factory by endpoint
            ChannelFactory<IEvalService> factory2 = new ChannelFactory<IEvalService>(new WSHttpBinding(), "http://localhost:8080/evals/wsconfig");

            // channel - basic, hidden IClientChannel
            ///////////////////////////////////////////////////
            IEvalService channel1 = factory1.CreateChannel();

            try
            {
                channel1.GetEvals();

                Eval eval = new Eval();
                eval.Submitter = "Jay";
                eval.Timesent = DateTime.Now;
                eval.Comments = "One eval to rule them alll!!!!!!!!!";

                channel1.SubmitEval(eval);
                channel1.SubmitEval(eval);

                Console.ReadLine();

                ((IClientChannel)channel1).Close();
            }
            catch (Exception)
            {
                ((IClientChannel)channel1).Abort();
            }

            // channel client - integrated IClientChannel
            ///////////////////////////////////////////////////
            ChannelFactory<IEvalServiceChannel> factory3 = new ChannelFactory<IEvalServiceChannel>("BasicHttpBinding_IEvalService");

            IEvalServiceChannel channel2 = factory3.CreateChannel();

            try
            {
                Eval[] evals = channel2.GetEvals();
                Console.WriteLine("Number of evals: {0}", evals.Length);

                Console.ReadLine();

                channel2.Close();
            }
            catch (Exception)
            {
                channel2.Abort();
            }

            // proxy client
            ///////////////////////////////////////////////////
            EvalServiceClient client1 = new EvalServiceClient("BasicHttpBinding_IEvalService");

            try
            {
                Eval[] evals = client1.GetEvals();
                Console.WriteLine("Number of evals: {0}", evals.Length);

                Console.ReadLine();

                client1.Close();
            }
            catch (Exception)
            {
                client1.Abort();
            }
        }
        static void Main(string[] args)
        {
            //var cf = new ChannelFactory<IEvalServiceChannel>("End4");
            //var service = cf.CreateChannel();

            var endpoints = MetadataResolver.Resolve(typeof (IEvalService),
                new EndpointAddress("http://localhost:8085/evals/mex"));

            foreach (var endpoint in endpoints)
            {
                var service = new EvalServiceClient(endpoint.Binding, endpoint.Address);

                try
                {
                    var newEval = new Eval
                    {
                        Comments = "Testing",
                        Submitter = "Rafael",
                        Timesent = DateTime.Now
                    };

                    service.SubmitEval(newEval);
                    service.SubmitEval(newEval);

                    //var evals = service.GetEvals();
                    service.GetEvalsCompleted += service_GetEvalsCompleted;
                    service.GetEvalsAsync();

                    Console.WriteLine("Waiting...");

                    //Thread.Sleep(10000);
                    Console.WriteLine("Waiting More...");

                    //Console.ReadLine();
                    //foreach (var eval in evals)
                    //{
                    //    Console.WriteLine(eval.Submitter + " " + eval.Comments);
                    //}

                    service.Close();
                }
                catch (FaultException exception)
                {
                    Console.WriteLine("Ops... Something went wrong");
                    Console.WriteLine(exception);
                    service.Abort();
                }
                catch (CommunicationException exception)
                {
                    Console.WriteLine("Ops... Something went wrong");
                    Console.WriteLine(exception);
                    service.Abort();
                }
                catch (TimeoutException exception)
                {
                    Console.WriteLine("Ops... Something went wrong");
                    Console.WriteLine(exception);
                    service.Abort();
                }

                Console.ReadLine();
            }
        }