Exemplo n.º 1
0
        public void CallbackExample2()
        {
            //Start service and use net.tcp binding
            ServiceHost   eventServiceHost  = new ServiceHost(typeof(GreetingsService2));
            NetTcpBinding tcpBindingpublish = new NetTcpBinding();

            tcpBindingpublish.Security.Mode = SecurityMode.None;
            eventServiceHost.AddServiceEndpoint(typeof(IGreetings2), tcpBindingpublish, "net.tcp://localhost:8000/GreetingsService2");
            eventServiceHost.Open();

            //Create client proxy
            NetTcpBinding clientBinding = new NetTcpBinding();

            clientBinding.Security.Mode = SecurityMode.None;
            EndpointAddress ep    = new EndpointAddress("net.tcp://localhost:8000/GreetingsService2");
            ClientCallback2 cb    = new ClientCallback2();
            IGreetings2     proxy = DuplexChannelFactory <IGreetings2> .CreateChannel(new InstanceContext (cb), clientBinding, ep);

            //Call service
            proxy.SendMessage();

            //Wait for callback - sort of hack, but better than using wait handle to possibly block tests.
            Thread.Sleep(2000);

            //Cleanup
            eventServiceHost.Close();

            Assert.IsTrue(CallbackSent2, "#1");
            Assert.IsTrue(CallbackReceived2, "#2");
        }
		public void CallbackExample2 ()
		{
			//Start service and use net.tcp binding
			ServiceHost eventServiceHost = new ServiceHost (typeof (GreetingsService2));
			NetTcpBinding tcpBindingpublish = new NetTcpBinding ();
			tcpBindingpublish.Security.Mode = SecurityMode.None;
			eventServiceHost.AddServiceEndpoint (typeof (IGreetings2), tcpBindingpublish, "net.tcp://localhost:8000/GreetingsService2");
			eventServiceHost.Open ();

			//Create client proxy
			NetTcpBinding clientBinding = new NetTcpBinding ();
			clientBinding.Security.Mode = SecurityMode.None;
			EndpointAddress ep = new EndpointAddress ("net.tcp://localhost:8000/GreetingsService2");
			ClientCallback2 cb = new ClientCallback2 ();
			IGreetings2 proxy = DuplexChannelFactory<IGreetings2>.CreateChannel (new InstanceContext (cb), clientBinding, ep);

			//Call service
			proxy.SendMessage ();

			//Wait for callback - sort of hack, but better than using wait handle to possibly block tests.
			Thread.Sleep (2000);

			//Cleanup
			eventServiceHost.Close ();

			Assert.IsTrue (CallbackSent2, "#1");
			Assert.IsTrue (CallbackReceived2, "#2");
		}