Пример #1
0
        public void FourClientsOneServer()
        {
            int    threadCount = 4;
            int    reps        = 4;
            string uri         = "http://localhost:18080/";
            var    threads     = new Thread[threadCount];
            var    container   = new ServiceContainer();

            container.AddEndpoint(new Endpoint("Test", typeof(ITest), new DelegateServiceFactory(c => new MultiClientTest(), _ => { })));
            using (var server = new HttpListenerHost(uri, container)) {
                for (int i = 0; i < threadCount; i++)
                {
                    var inner = i;
                    threads[i] = new Thread(() =>
                    {
                        Console.WriteLine(Thread.CurrentThread.ManagedThreadId);
                        var client = new Client <ITest>(uri + "Test");
                        for (int j = 0; j < reps; j++)
                        {
                            client.Proxy().VoidStringParam(inner.ToString() + " rep: " + j.ToString());
                        }
                    });
                    threads[i].Start();
                }
                foreach (var thread in threads)
                {
                    thread.Join();
                }
            }
        }
Пример #2
0
        private string TestMethod(string payload)
        {
            var container = new ServiceContainer();
            var factory   = new DelegateServiceFactory(c => { return(new HappyPathService()); }, _ => { return; });

            container.AddEndpoint(new Endpoint("Happy", typeof(IHappyPath), factory));

            using (var host = new HttpListenerHost(string.Format(happyPathURI, port), container))
            {
                return(Execute(payload));
            }
        }
Пример #3
0
        static void Main(string[] args)
        {
            var container = new ServiceContainer();
            var pipe      = new Pipeline(typeof(IExample), new JsonSerializer(), new DelegateServiceFactory(c => new ExampleService(), _ => { }), new DefaultInvoker());
            var endpoint  = new Endpoint("Example", typeof(IExample), pipe);

            container.AddEndpoint(endpoint);
            using (var host = new HttpListenerHost(Consts.URI, container))
            {
                Console.WriteLine("Host open");
                Console.ReadKey();
            }
        }
Пример #4
0
        public void CanAttachHeaderdataToServer()
        {
            string uri       = "http://localhost:18081/";
            var    container = new ServiceContainer();

            container.AddEndpoint(new Endpoint("Test", typeof(ITest), new DelegateServiceFactory(c => new HeaderdataTestService(c), service => { })));
            using (var server = new HttpListenerHost(uri, container))
            {
                var proxy = new Client <ITest>(uri + "Test");
                proxy.RequestHeaderdata.Add("akey", "avalue");
                proxy.Proxy().VoidNoParam();
                //service.AValue.ShouldEqual("avalue");
            }
        }
Пример #5
0
        public void CanAttachHeaderdataToReply()
        {
            string uri       = "http://localhost:18082/";
            var    container = new ServiceContainer();

            container.AddEndpoint(new Endpoint("Test", typeof(ITest), new DelegateServiceFactory(c => new HeaderdataTestService(c), service => {  })));
            using (var server = new HttpListenerHost(uri, container))
            {
                var proxy = new Client <ITest>(uri + "Test");
                proxy.Proxy().VoidStringParam("avalue");
                var response = proxy.ResponseHeaderdata["akey"];
                response.ShouldEqual("avalue");
            }
        }
Пример #6
0
        public void CanCallWithProxy()
        {
            var container = new ServiceContainer();
            var factory   = new DelegateServiceFactory(c => { return(new HappyPathService()); }, _ => { return; });

            container.AddEndpoint(new Endpoint("Happy", typeof(IHappyPath), factory));

            using (var host = new HttpListenerHost(string.Format(happyPathURI, port), container))
            {
                var client = new Client <IHappyPath>(string.Format(happyPathURI, port) + "Happy");
                var result = client.Proxy().Complex(new Complex {
                    Data = "hej", Value = 6004
                });
                result.Value.ShouldEqual(12008);
                result.Data.ShouldEqual("hej6004");
            }
        }