public ActionResult Hello()
        {
            string result       = "*No Response*";
            string endpointName = null;

            try
            {
                endpointName = GlobalCache.GetResolvedString("EchoServiceEndpoint");
                if (endpointName == null)
                {
                    throw new ApplicationException("Could not find 'EchoServiceEndpoint' in configuration settings.");
                }
                Debug.WriteLine(string.Format("EchoServiceEndpoint='{0}'", endpointName));

                // ---------------------------------------------------------
                //
                // ---------------------------------------------------------
                using (EchoServiceClient proxy = new EchoServiceClient(endpointName))
                {
                    result = proxy.Ping();
                }
            }
            catch (Exception exp)
            {
                Request.PostError(exp);
            }

            return(View("Hello", (object)$"Endpoint: {endpointName ?? "*Unknown*"}, Result: {result}"));
        }
Example #2
0
        public void Run()
        {
            try
            {
                using (EchoServiceClient proxy = new EchoServiceClient(_echoServiceEndpointName))
                {
                    string result = "";

                    result = proxy.Ping();
                    Console.WriteLine(string.Format("EchoService : {0}", result));
                }
            }
            catch (System.ServiceModel.EndpointNotFoundException)
            {
                Trace.WriteLine(string.Format("!Note! : No endpoint listening at [{0}]", _echoServiceEndpointName));
            }

            using (LibraryServiceClient proxy = new LibraryServiceClient(_libraryServiceEndpointName))
            {
                Book book = null;

                Action prompt = new Action(() =>
                {
                    Console.WriteLine("LIST - Return a list of Books using the Search Pattern.");
                    Console.WriteLine("READ - Return a Book using the Key value.");
                    Console.WriteLine("Press ENTER to terminate.");
                });

                prompt();

                string        input = "";
                StringBuilder sb    = new StringBuilder();
                while ((input = Console.ReadLine().ToUpper()).Length > 0)
                {
                    try
                    {
                        string[] tokens = input.Split(' ');
                        switch ((tokens.Length) > 0 ? tokens[0] : "")
                        {
                        case "LIST":
                            Console.Write("Search Pattern : ");
                            string searchPattern = Console.ReadLine();
                            proxy.List(searchPattern, out books);

                            Stream stream = new MemoryStream();
                            EntitySerializationHelpers.SerializeBooks(books.ToList(), stream);
                            Console.WriteLine(stream.ContentsToString());

                            break;

                        case "LOAD":
                            Stream xstream = StreamFactory.Create(@"res://AppData.Books.xml");
                            Console.WriteLine(string.Format("Load = {0}", proxy.Load(xstream)));
                            break;

                        case "READ":
                            Console.Write("Key : ");
                            string key = Console.ReadLine();
                            if (proxy.Read(key, out book))
                            {
                                stream = new MemoryStream();
                                EntitySerializationHelpers.SerializeBook(book, stream);
                                Console.WriteLine(stream.ContentsToString());
                            }
                            else
                            {
                                Console.WriteLine(" *Not Found*");
                            }
                            break;

                        default:
                            prompt();
                            break;
                        }
                    }
                    catch (Exception exp)
                    {
                        Trace.WriteLine(string.Format("Error {0} : {1}", input, exp.Message));
                    }
                }
            }
        }