Example #1
0
        static void Main(string[] args)
        {
            string      baseAddress = "http://" + Environment.MachineName + ":8000/Service";
            ServiceHost host        = new ServiceHost(typeof(Service), new Uri(baseAddress));

            host.AddServiceEndpoint(typeof(ITest), new BasicHttpBinding(), "");
            host.Open();
            WriteLine("Host opened");

            ChannelFactory <ITest> factory = new ChannelFactory <ITest>(new BasicHttpBinding(), new EndpointAddress(baseAddress));
            ITest proxy = factory.CreateChannel();

            WriteLine("Add(4, 5): {0}", proxy.Add(4, 5));
            WriteLine("Add(4, 5): {0}", proxy.Add(4, 5));

            AutoResetEvent evt = new AutoResetEvent(false);

            proxy.BeginPower(2, 64, delegate(IAsyncResult asyncResult)
            {
                WriteLine("Pow(2, 64): {0}", proxy.EndPower(asyncResult));
                evt.Set();
            }, null);
            evt.WaitOne();

            proxy.BeginPower(2, 64, delegate(IAsyncResult asyncResult)
            {
                WriteLine("Pow(2, 64): {0}", proxy.EndPower(asyncResult));
                evt.Set();
            }, null);
            evt.WaitOne();

            WriteLine("Reverse(\"Hello world\"): {0}", proxy.Reverse("Hello world"));
            WriteLine("Reverse(\"Hello world\"): {0}", proxy.Reverse("Hello world"));

            int i;

            WriteLine("TryParseInt(123): {0}, {1}", proxy.TryParseInt("123", out i), i);
            WriteLine("TryParseInt(123): {0}, {1}", proxy.TryParseInt("123", out i), i);

            proxy.BeginTryParseDouble("34.567", delegate(IAsyncResult asyncResult)
            {
                double dbl;
                WriteLine("TryParseDouble(34.567): {0}, {1}", proxy.EndTryParseDouble(out dbl, asyncResult), dbl);
                evt.Set();
            }, null);
            evt.WaitOne();

            proxy.BeginTryParseDouble("34.567", delegate(IAsyncResult asyncResult)
            {
                double dbl;
                WriteLine("TryParseDouble(34.567): {0}, {1}", proxy.EndTryParseDouble(out dbl, asyncResult), dbl);
                evt.Set();
            }, null);
            evt.WaitOne();

            WriteLine("Press ENTER to close");
            Console.ReadLine();
            host.Close();
        }
Example #2
0
        public static void Test()
        {
            string      baseAddress = "http://" + Environment.MachineName + ":8000/Service";
            ServiceHost host        = new ServiceHost(typeof(Service), new Uri(baseAddress));

            host.AddServiceEndpoint(typeof(ITest), GetBinding(), "");
            host.Description.Behaviors.Add(new ServiceMetadataBehavior {
                HttpGetEnabled = true
            });
            host.Open();
            Console.WriteLine("Host opened");

            ChannelFactory <ITest> factory = new ChannelFactory <ITest>(GetBinding(), new EndpointAddress(baseAddress));
            ITest proxy = factory.CreateChannel();

            Console.WriteLine(proxy.Add(5, 8));

            var p = new Person {
                Name = "John Doe", Age = 33
            };
            var p2 = proxy.EchoPerson(p);

            Console.WriteLine("Person[Name={0}, Age={1}]", p2.Name, p2.Age);

            ((IClientChannel)proxy).Close();
            factory.Close();

            Console.Write("Press ENTER to close the host");
            Console.ReadLine();
            host.Close();
        }
Example #3
0
        public async Task ProxyWorks()
        {
            Test  t  = new Test();
            ITest tp = FiberProxy <ITest> .Create(t);

            tp.Init();
            tp.Add(1);
            tp.Subtract(2);
            await Task.Delay(100);

            Assert.IsTrue(t.Inited);
            Assert.AreEqual(-1, t.Count);
            int result = 0;

            tp.Event1 += x => result = x;

            t.Trigger();
            await Task.Delay(100);

            Assert.AreEqual(1, result);

            tp.Dispose();
            Assert.IsTrue(t.Inited);
            Assert.AreEqual(-1, t.Count);
            Assert.IsTrue(t.Disposed);
        }
Example #4
0
        static void Main(string[] args)
        {
            string baseAddress = "http://" + Environment.MachineName + ":8000/Service";

            foreach (Type badServiceType in new Type[] { typeof(BadService1_NoDefaultCtor), typeof(BadService2_RefParameter) })
            {
                try
                {
                    new PocoServiceHost(badServiceType, new Uri(baseAddress)).Open();
                    Console.WriteLine("This line should not be reached");
                }
                catch (InvalidOperationException e)
                {
                    Console.WriteLine("Caught expected exception for service {0}: {1}", badServiceType.Name, e.Message);
                }
            }

            PocoServiceHost host = new PocoServiceHost(typeof(Service), new Uri(baseAddress));

            host.Open();

            ChannelFactory <ITest> factory = new ChannelFactory <ITest>(new BasicHttpBinding(), new EndpointAddress(baseAddress));
            ITest proxy = factory.CreateChannel();

            Console.WriteLine(proxy.Add(4, 5));
            Console.WriteLine(proxy.Distance(new Point {
                X = 0, Y = 0
            }, new Point {
                X = 3, Y = 4
            }));

            Console.WriteLine("Press ENTER to close");
            Console.ReadLine();
            host.Close();
        }
Example #5
0
        static void Main(string[] args)
        {
            string          baseAddress = "http://" + Environment.MachineName + ":8000/Service";
            ServiceHost     host        = new ServiceHost(typeof(Service), new Uri(baseAddress));
            ServiceEndpoint endpoint    = host.AddServiceEndpoint(typeof(ITest), new WebHttpBinding(), "");

            endpoint.Behaviors.Add(new WebHttpBehavior());
            endpoint.Behaviors.Add(new MyInspector());
            host.Open();
            Console.WriteLine("Host opened");

            ChannelFactory <ITest> factory = new ChannelFactory <ITest>(new WebHttpBinding(), new EndpointAddress(baseAddress));

            factory.Endpoint.Behaviors.Add(new WebHttpBehavior());
            ITest proxy = factory.CreateChannel();

            Console.WriteLine(proxy.Echo("Hello"));
            Console.WriteLine(proxy.LongEcho("World", 1234));
            Console.WriteLine(proxy.Add(3, 4));

            ((IClientChannel)proxy).Close();
            factory.Close();

            Console.Write("Press ENTER to close the host");
            Console.ReadLine();
            host.Close();
        }
Example #6
0
        /* Here is the bussiness logic for our application */
        public async Task Run()
        {
            _logger.LogInformation("The main logic is starting now!");

            _test.Add();

            await Task.Delay(1000);

            _logger.LogInformation("The application stop now!");
        }
Example #7
0
        static void Main(string[] args)
        {
            var serviceCollection = new ServiceCollection();

            serviceCollection.AddSingleton <ITest, Test>();
            serviceCollection.AddSingleton <ICoty, Coty>();
            ServiceProvider serviceProvider = serviceCollection.BuildServiceProvider();
            ITest           serviceHost     = serviceProvider.GetRequiredService <ITest>();

            serviceHost.Add();
        }
        static void Main(string[] args)
        {
            string baseAddress = "http://" + Environment.MachineName + ":8000/Service";

            using (ServiceHost host = new ServiceHost(typeof(Service), new Uri(baseAddress)))
            {
                ServiceEndpoint endpoint = host.AddServiceEndpoint(typeof(ITest), new BasicHttpBinding(), "");
                endpoint.Contract.Behaviors.Add(new MyBehavior());
                foreach (OperationDescription operation in endpoint.Contract.Operations)
                {
                    operation.Behaviors.Add(new MyBehavior());
                }

                var polices = new List <IAuthorizationPolicy>();
                polices.Add(new MyAuthorizationPolicy());
                host.Authorization.ExternalAuthorizationPolicies = polices.AsReadOnly();

                host.Open();
                ColorConsole.WriteLine("Host opened");

                using (ChannelFactory <ITest> factory = new ChannelFactory <ITest>(new BasicHttpBinding(), new EndpointAddress(baseAddress)))
                {
                    factory.Endpoint.Contract.Behaviors.Add(new MyBehavior());
                    foreach (OperationDescription operation in factory.Endpoint.Contract.Operations)
                    {
                        operation.Behaviors.Add(new MyBehavior());
                    }

                    ITest proxy = factory.CreateChannel();
                    ColorConsole.WriteLine("Calling operation");
                    ColorConsole.WriteLine(proxy.Add(3, 4));

                    //ColorConsole.WriteLine("Called operation, calling it again, this time it the service will throw");
                    //try
                    //{
                    //    ColorConsole.WriteLine(proxy.Add(0, 0));
                    //}
                    //catch (Exception e)
                    //{
                    //    ColorConsole.WriteLine(ConsoleColor.Red, "{0}: {1}", e.GetType().Name, e.Message);
                    //}

                    //ColorConsole.WriteLine("Now calling an OneWay operation");
                    //proxy.Process("hello");

                    ((IClientChannel)proxy).Close();
                }
            }

            ColorConsole.WriteLine("Done");
        }
Example #9
0
        public static void Main(string[] args)
        {
            const int size = 10000;

            for (int i = 0; i < TestCount; i++)
            {
                AddTickSum[i]   = 0;
                ReachTickSum[i] = 0;
            }

            for (int i = 0; i < Repeat; i++)
            {
                _dictionaryTests = new DictionaryTests(size);
                AddTickSum[0]   += _dictionaryTests.Add();
                ReachTickSum[0] += _dictionaryTests.Reach();

                _hashSetTests    = new HashSetTests(size);
                AddTickSum[1]   += _hashSetTests.Add();
                ReachTickSum[1] += _hashSetTests.Reach();

                _listTests       = new ListTests(size);
                AddTickSum[2]   += _listTests.Add();
                ReachTickSum[2] += _listTests.Reach();

                _linkedListTests = new LinkedListTests(size);
                AddTickSum[3]   += _linkedListTests.Add();
                ReachTickSum[3] += _linkedListTests.Reach();

                _queueTests      = new QueueTests(size);
                AddTickSum[4]   += _queueTests.Add();
                ReachTickSum[4] += _queueTests.Reach();

                _stackTests      = new StackTests(size);
                AddTickSum[5]   += _stackTests.Add();
                ReachTickSum[5] += _stackTests.Reach();
            }

            for (int i = 0; i < TestCount; i++)
            {
                Console.WriteLine(AddTickSum[i] / Repeat);
                Console.WriteLine(ReachTickSum[i] / Repeat);
            }
        }
        public IEnumerable <WeatherForecast> Get()
        {
            var result = _test.Add(1, 2);

            foreach (var v in _tests)
            {
                result = v.Add(2, 3);
            }


            var rng = new Random();

            return(Enumerable.Range(1, 5).Select(index => new WeatherForecast
            {
                Date = DateTime.Now.AddDays(index),
                TemperatureC = rng.Next(-20, 55),
                Summary = Summaries[rng.Next(Summaries.Length)]
            })
                   .ToArray());
        }
Example #11
0
        public static void Test()
        {
            string      baseAddress = "http://" + Environment.MachineName + ":8000/Service";
            ServiceHost host        = new ServiceHost(typeof(Service), new Uri(baseAddress));

            host.AddServiceEndpoint(typeof(ITest), GetBinding(), "");
            host.Open();
            Console.WriteLine("Host opened");

            ChannelFactory <ITest> factory = new ChannelFactory <ITest>(GetBinding(), new EndpointAddress(baseAddress));
            ITest proxy = factory.CreateChannel();

            Console.WriteLine(proxy.Add(5, 8));

            ((IClientChannel)proxy).Close();
            factory.Close();

            Console.Write("Press ENTER to close the host");
            Console.ReadLine();
            host.Close();
        }
        static void Main(string[] args)
        {
            string baseAddress = "http://" + Environment.MachineName + ":8000/Service";

            using (ServiceHost host = new ServiceHost(typeof(Service), new Uri(baseAddress)))
            {
                ServiceEndpoint endpoint = host.AddServiceEndpoint(typeof(ITest), new BasicHttpBinding(), "");
                endpoint.Contract.Behaviors.Add(new MyBehavior());
                foreach (OperationDescription operation in endpoint.Contract.Operations)
                {
                    operation.Behaviors.Add(new MyBehavior());
                }

                host.Open();
                ColorConsole.WriteLine("Host opened");

                using (ChannelFactory <ITest> factory = new ChannelFactory <ITest>(new BasicHttpBinding(), new EndpointAddress(baseAddress)))
                {
                    factory.Endpoint.Contract.Behaviors.Add(new MyBehavior());
                    foreach (OperationDescription operation in factory.Endpoint.Contract.Operations)
                    {
                        operation.Behaviors.Add(new MyBehavior());
                    }

                    ITest proxy = factory.CreateChannel();
                    ColorConsole.WriteLine("Calling operation");
                    ColorConsole.WriteLine(proxy.Add(3, 4));

                    Console.WriteLine();
                    Console.WriteLine("   *-*-*-*-*-*-*-*-*-*-*-*-*-*-*");
                    Console.WriteLine();

                    ColorConsole.WriteLine("Called operation, calling it again, this time it the service will throw");
                    try
                    {
                        ColorConsole.WriteLine(proxy.Add(0, 0));
                    }
                    catch (Exception e)
                    {
                        ColorConsole.WriteLine(ConsoleColor.Red, "{0}: {1}", e.GetType().Name, e.Message);
                    }

                    Console.WriteLine();
                    Console.WriteLine("   *-*-*-*-*-*-*-*-*-*-*-*-*-*-*");
                    Console.WriteLine();

                    ColorConsole.WriteLine("Now calling an OneWay operation");
                    proxy.Process("hello");
                    Thread.Sleep(5000);

                    Console.WriteLine();
                    Console.WriteLine("   *-*-*-*-*-*-*-*-*-*-*-*-*-*-*");
                    Console.WriteLine();

                    ManualResetEvent evt = new ManualResetEvent(false);
                    ColorConsole.WriteLine("Now calling an asynchronous operation");
                    proxy.BeginEcho("hello", delegate(IAsyncResult ar)
                    {
                        Console.WriteLine(proxy.EndEcho(ar));
                        evt.Set();
                    }, null);

                    evt.WaitOne();

                    ((IClientChannel)proxy).Close();
                }
            }

            ColorConsole.WriteLine("Done");
        }
Example #13
0
        public ActionResult Index()
        {
            ViewBag.Title = test.Add(1, 1);

            return(View());
        }
Example #14
0
 public string Test(string id)
 {
     return(_test.Add(id));
 }
 public string Test(string name, int id, double cardId, string pwd)
 {
     return(_test.Add());
 }
Example #16
0
 private static void SomeMethod(ITest <string> test)
 {
     test.Add(1, "test");
 }