Пример #1
0
        public void RoutingDefault()
        {
            var routerPath = new Uri("net.tcp://localhost:9000/gateway");

            var service1 = FooService.Create("net.tcp://localhost:8080/bar");
            service1.Service.StartAsync().Wait();
            var service2 = FooService.Create("net.tcp://localhost:8081/baz");
            service2.Service.StartAsync().Wait();

            var resolver = new TestResolver(service1, service2);
            var gateway = new TcpRouter();

            gateway.Initialize(routerPath, resolver);

            gateway.Service.StartAsync().Wait();

            var clientPath = new Uri("net.tcp://localhost/bar");
            TcpClient<IFoo> client;
            var clientCreateResult = TcpClient<IFoo>.TryCreate(clientPath, routerPath, out client);
            Assert.IsTrue(clientCreateResult);
            client.Instance.SetName("routed bar");

            // verify it's set
            Assert.AreEqual("routed bar", service1.Instance.Name);
        }
Пример #2
0
        // Hello World with the Routing Service
        // https://msdn.microsoft.com/en-us/library/dd795218%28v=vs.110%29.aspx
        static void Routing()
        {
            var routerPath = new Uri("net.tcp://localhost:9000/");

            var service1 = FooService.Create("net.tcp://localhost:8080/bar");
            service1.Service.StartAsync().Wait();
            var service2 = FooService.Create("net.tcp://localhost:8081/baz");
            service2.Service.StartAsync().Wait();

            var resolver = new TestResolver(service1, service2);
            var gateway = new TcpRouter();

            gateway.Initialize(routerPath, resolver);
            gateway.Service.StartAsync().Wait();

            var clientPath = new Uri("net.tcp://localhost/bar");
            TcpClient<IFoo> client;
            var clientCreateResult = TcpClient<IFoo>.TryCreate(clientPath, routerPath, out client);
            client.Instance.SetName("routed bar");

            // verify it's set
            if (!service1.Instance.Name.Equals("routed bar"))
                throw new ApplicationException("name not set");
        }