Exemplo n.º 1
0
        public void InvokeOtherService()
        {
            var address = @"net.pipe://127.0.0.1/1/test.test/test" + MethodBase.GetCurrentMethod().Name;
            var otherAddress = @"net.pipe://127.0.0.1/1/test.test/other" + MethodBase.GetCurrentMethod().Name;
            var wait = new ManualResetEvent(false);
            var srv = new Service(null);
            var otherSrv = new OtherService(wait);
            var host = new ServiceHost(srv, new Uri(address));
            var b = new NetNamedPipeBinding();
            host.AddServiceEndpoint(typeof(IService), b, address);
            var otherHost = new ServiceHost(otherSrv, new Uri(address));

            otherHost.AddServiceEndpoint(typeof(IOtherService), b, otherAddress);
            var f = new ChannelFactory<IService>(b);
            var c = f.CreateChannel(new EndpointAddress(address));

            host.Open();
            otherHost.Open();
            c.CallOtherService(otherAddress);
            wait.WaitOne();
            host.Dispose();
            otherHost.Dispose();
        }