Example #1
1
        static EndpointAddress FindCalculatorServiceAddress()
        {
            // Create DiscoveryClient
            DiscoveryEndpoint discoveryEndpoint = new DiscoveryEndpoint(new NetTcpBinding(), new EndpointAddress("net.tcp://localhost:8001/DiscoveryRouter/"));
            DiscoveryClient discoveryClient = new DiscoveryClient(discoveryEndpoint);

            Console.WriteLine("Finding ICalculatorService endpoints...");
            Console.WriteLine();

            // Find ICalculatorService endpoints            
            FindCriteria findCriteria = new FindCriteria(typeof(ICalculatorService));
            findCriteria.Duration = TimeSpan.FromSeconds(10);

            FindResponse findResponse = discoveryClient.Find(findCriteria);

            Console.WriteLine("Found {0} ICalculatorService endpoint(s).", findResponse.Endpoints.Count);
            Console.WriteLine();

            if (findResponse.Endpoints.Count > 0)
            {
                return findResponse.Endpoints[0].Address;
            }
            else
            {
                return null;
            }
        }
		private DiscoveryEndpoint DiscoverEndpoint(DiscoveryEndpoint endpoint, bool required)
		{
			using (var discover = new DiscoveryClient(UdpDiscoveryEndpoint ?? new UdpDiscoveryEndpoint()))
			{
				var criteria = new FindCriteria(endpoint.Contract.ContractType) { MaxResults = 1 };
				if (DiscoveryDuration.HasValue)
				{
					criteria.Duration = DiscoveryDuration.Value;
				}

				var discovered = discover.Find(criteria);
				if (discovered.Endpoints.Count > 0)
				{
					var endpointMetadata = discovered.Endpoints[0];
					var binding = Binding ?? AbstractChannelBuilder.GetBindingFromMetadata(endpointMetadata);
					return new DiscoveryEndpoint(binding, endpointMetadata.Address);
				}

				if (required)
				{
					throw new EndpointNotFoundException("Unable to locate a ServiceCatalog on the network.");
				}

				return null;
			}
		}
		void UseCase1Core (Uri serviceUri, AnnouncementEndpoint aEndpoint, DiscoveryEndpoint dEndpoint)
		{
			// actual service, announcing to 4989
			var host = new ServiceHost (typeof (TestService));
			var sdb = new ServiceDiscoveryBehavior ();
			sdb.AnnouncementEndpoints.Add (aEndpoint);
			host.Description.Behaviors.Add (sdb);
			host.AddServiceEndpoint (typeof (ITestService), new BasicHttpBinding (), serviceUri);
			host.Open ();
			// It does not start announcement very soon, so wait for a while.
			Thread.Sleep (1000);
			foreach (var edm in host.Extensions.Find<DiscoveryServiceExtension> ().PublishedEndpoints)
				TextWriter.Null.WriteLine ("Published Endpoint: " + edm.Address);
			try {
				// actual client, with DiscoveryClientBindingElement
				var be = new DiscoveryClientBindingElement () { DiscoveryEndpointProvider = new ManagedDiscoveryEndpointProvider (dEndpoint) };
				var clientBinding = new CustomBinding (new BasicHttpBinding ());
				clientBinding.Elements.Insert (0, be);
				var cf = new ChannelFactory<ITestService> (clientBinding, DiscoveryClientBindingElement.DiscoveryEndpointAddress);
				var ch = cf.CreateChannel ();
				Assert.AreEqual ("TEST", ch.Echo ("TEST"), "#1");
			} finally {
				host.Close ();
			}
		}
Example #4
0
        static void Main(string[] args)
        {
            // Create a DiscoveryEndpoint that points to the DiscoveryProxy
            Uri probeEndpointAddress = new Uri("net.tcp://localhost:8001/Probe");
            DiscoveryEndpoint discoveryEndpoint = new DiscoveryEndpoint(new NetTcpBinding(), new EndpointAddress(probeEndpointAddress));

            DiscoveryClient discoveryClient = new DiscoveryClient(discoveryEndpoint);

            Console.WriteLine("Finding ICalculatorService endpoints using the proxy at {0}", probeEndpointAddress);
            Console.WriteLine();

            try
            {
                // Find ICalculatorService endpoints
                FindResponse findResponse = discoveryClient.Find(new FindCriteria(typeof(ICalculatorService)));

                Console.WriteLine("Found {0} ICalculatorService endpoint(s).", findResponse.Endpoints.Count);
                Console.WriteLine();

                // Check to see if endpoints were found, if so then invoke the service.
                if (findResponse.Endpoints.Count > 0)
                {
                    InvokeCalculatorService(findResponse.Endpoints[0].Address);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("This client was unable to connect to and query the proxy. Ensure that the proxy is up and running.");
            }

            Console.WriteLine("Press <ENTER> to exit.");
            Console.ReadLine();
        }
Example #5
0
        public static void Main()
        {
            var dnsName = Dns.GetHostName();
            // Create a DiscoveryEndpoint that points to the DiscoveryProxy
            var probeEndpointAddress = new Uri(string.Format("http://{0}:8001/Probe", dnsName));
            var discoveryEndpoint = new DiscoveryEndpoint(new BasicHttpBinding(), new EndpointAddress(probeEndpointAddress));

            var discoveryClient = new DiscoveryClient(discoveryEndpoint);

            Console.WriteLine("Finding ICalculatorService endpoints using the proxy at {0}", probeEndpointAddress);
            Console.WriteLine();

            try
            {
                // Find ICalculatorService endpoints
                FindResponse findResponse = discoveryClient.Find(new FindCriteria(typeof(ICalculatorService)));

                Console.WriteLine("Found {0} ICalculatorService endpoint(s).", findResponse.Endpoints.Count);
                Console.WriteLine();

                // Check to see if endpoints were found, if so then invoke the service.
                if (findResponse.Endpoints.Count > 0)
                {
                    InvokeCalculatorService(findResponse.Endpoints[0].Address);
                }
            }
            catch (TargetInvocationException)
            {
                Console.WriteLine("This client was unable to connect to and query the proxy. Ensure that the proxy is up and running.");
            }

            Console.WriteLine("Press <ENTER> to exit.");
            Console.ReadLine();
        }
Example #6
0
        private static ServiceHost HostDiscoveryEndpoint(string hostName)
        {
            // Create a new ServiceHost with a singleton ChatDiscovery Proxy
            ServiceHost myProxyHost = new
                ServiceHost(new ChatDiscoveryProxy());

            string proxyAddress = "net.tcp://" +
                hostName + ":8001/discoveryproxy";

            // Create the discovery endpoint
            DiscoveryEndpoint discoveryEndpoint =
                new DiscoveryEndpoint(
                    new NetTcpBinding(),
                    new EndpointAddress(proxyAddress));

            discoveryEndpoint.IsSystemEndpoint = false;

            // Add UDP Annoucement endpoint
            myProxyHost.AddServiceEndpoint(new UdpAnnouncementEndpoint());

            // Add the discovery endpoint
            myProxyHost.AddServiceEndpoint(discoveryEndpoint);

            myProxyHost.Open();
            Console.WriteLine("Discovery Proxy {0}",
                proxyAddress);

            return myProxyHost;
        }
Example #7
0
        public static void Main()
        {
            Uri probeEndpointAddress = new Uri("net.tcp://localhost:8001/Probe");
            DiscoveryEndpoint discoveryEndpoint = new DiscoveryEndpoint(new NetTcpBinding(), new EndpointAddress(probeEndpointAddress));

            DiscoveryClient discoveryClient = new DiscoveryClient(discoveryEndpoint);

            Console.WriteLine("Finding ICalculatorService endpoints using the proxy at {0}", probeEndpointAddress);
            Console.WriteLine();

            try
            {
                FindResponse findResponse = discoveryClient.Find(new FindCriteria(typeof(ICalculator)));

                Console.WriteLine("Found {0} ICalculatorService endpoint(s).", findResponse.Endpoints.Count);
                Console.WriteLine();

                if (findResponse.Endpoints.Count > 0)
                {
                    InvokeCalculatorService(findResponse.Endpoints[0].Address);
                }
            }
            catch (TargetInvocationException)
            {
                Console.WriteLine("This client was unable to connect to and query the proxy. Ensure that the proxy is up and running.");
            }
        }
Example #8
0
	static void RunCodeUnderDiscoveryHost (Uri serviceUri, Uri aHostUri, Action<Uri,AnnouncementEndpoint,DiscoveryEndpoint> action)
	{
		var abinding = new CustomBinding (new HttpTransportBindingElement ());
		var aAddress = new EndpointAddress (aHostUri);
		var aEndpoint = new AnnouncementEndpoint (abinding, aAddress);
		var dBinding = new CustomBinding (new TextMessageEncodingBindingElement (), new TcpTransportBindingElement ());
		var dEndpoint = new DiscoveryEndpoint (DiscoveryVersion.WSDiscovery11, ServiceDiscoveryMode.Adhoc, dBinding, new EndpointAddress ("net.tcp://localhost:9090/"));

		var ib = new InspectionBehavior ();
		ib.RequestReceived += delegate (ref Message msg, IClientChannel
channel, InstanceContext instanceContext) {
			var mb = msg.CreateBufferedCopy (0x10000);
			msg = mb.CreateMessage ();
			Console.Error.WriteLine (mb.CreateMessage ());
			return null;
			};
		ib.ReplySending += delegate (ref Message msg, object o) {
			var mb = msg.CreateBufferedCopy (0x10000);
			msg = mb.CreateMessage ();
			Console.Error.WriteLine (mb.CreateMessage ());
			};
		dEndpoint.Behaviors.Add (ib);
		aEndpoint.Behaviors.Add (ib);

		action (serviceUri, aEndpoint, dEndpoint);
	}
Example #9
0
	static void RunCodeUnderDiscoveryHost (Uri serviceUri, Uri dHostUri, Action<Uri,AnnouncementEndpoint,DiscoveryEndpoint> action)
	{
		var aEndpoint = new UdpAnnouncementEndpoint (DiscoveryVersion.WSDiscoveryApril2005, new Uri ("soap.udp://239.255.255.250:3802/"));
		var dbinding = new CustomBinding (new HttpTransportBindingElement ());
		var dAddress = new EndpointAddress (dHostUri);
		var dEndpoint = new DiscoveryEndpoint (dbinding, dAddress);

		var ib = new InspectionBehavior ();
		ib.RequestReceived += delegate (ref Message msg, IClientChannel
channel, InstanceContext instanceContext) {
			var mb = msg.CreateBufferedCopy (0x10000);
			msg = mb.CreateMessage ();
			Console.Error.WriteLine (mb.CreateMessage ());
			return null;
			};
		ib.ReplySending += delegate (ref Message msg, object o) {
			var mb = msg.CreateBufferedCopy (0x10000);
			msg = mb.CreateMessage ();
			Console.Error.WriteLine (mb.CreateMessage ());
			};

		dEndpoint.Behaviors.Add (ib);
		aEndpoint.Behaviors.Add (ib);

		action (serviceUri, aEndpoint, dEndpoint);
	}
 public ManagedProxyDiscoveryServiceHost(IEndpointMetadataProvider endpointMetadataProvider, IDiscoveryServiceResolver discoveryServiceResolver, params PluginBase[] plugins)
     : base(new ManagedProxyDiscoveryService(endpointMetadataProvider, plugins))
 {
     var announcementEndpoint = new AnnouncementEndpoint(discoveryServiceResolver.AnnouncementBinding, new EndpointAddress(discoveryServiceResolver.AnnouncementEndpoint));
     var probeEndpoint = new DiscoveryEndpoint(discoveryServiceResolver.ProbeBinding, new EndpointAddress(discoveryServiceResolver.ProbeEndpoint));
     probeEndpoint.IsSystemEndpoint = false;
     AddServiceEndpoint(announcementEndpoint);
     AddServiceEndpoint(probeEndpoint);
 }
		public DiscoveryProxyEndpoint(DiscoveryEndpoint endpoint)
		{
			if (endpoint == null)
			{
				throw new ArgumentNullException("endpoint");
			}

			this.endpoint = endpoint;
		}
Example #12
0
	static void RunCodeUnderDiscoveryHost (Uri serviceUri, Uri dHostUri, Uri aHostUri, Action<Uri,AnnouncementEndpoint,DiscoveryEndpoint> action)
	{
		var abinding = new CustomBinding (new HttpTransportBindingElement ());
		var aAddress = new EndpointAddress (aHostUri);
		var aEndpoint = new AnnouncementEndpoint (abinding, aAddress);
		var dbinding = new CustomBinding (new HttpTransportBindingElement ());
		var dAddress = new EndpointAddress (dHostUri);
		var dEndpoint = new DiscoveryEndpoint (dbinding, dAddress);

		action (serviceUri, aEndpoint, dEndpoint);
	}
        void InitializeAndFindAsync()
        {
            DiscoveryEndpoint discoveryEndpoint = this.discoveryEndpointProvider.GetDiscoveryEndpoint();

            if (discoveryEndpoint == null)
            {
                throw FxTrace.Exception.AsError(
                          new InvalidOperationException(
                              SR.DiscoveryMethodImplementationReturnsNull("GetDiscoveryEndpoint", this.discoveryEndpointProvider.GetType())));
            }

            this.discoveryClient = new DiscoveryClient(discoveryEndpoint);
            this.discoveryClient.FindProgressChanged += new EventHandler <FindProgressChangedEventArgs>(OnFindProgressChanged);
            this.discoveryClient.FindCompleted       += new EventHandler <FindCompletedEventArgs>(OnFindCompleted);

            SynchronizationContext originalSynchronizationContext = SynchronizationContext.Current;

            if (originalSynchronizationContext != null)
            {
                SynchronizationContext.SetSynchronizationContext(null);

                if (TD.SynchronizationContextSetToNullIsEnabled())
                {
                    TD.SynchronizationContextSetToNull();
                }
            }

            try
            {
                // AsyncOperation uses the SynchronizationContext set during its
                // initialization to Post the FindProgressed and FindProgressCompleted
                // events. Hence even if the async operation does not complete
                // synchronously, the right SynchronizationContext will be used by
                // AsyncOperation.
                this.discoveryClient.FindAsync(this.findCriteria, this);
            }
            finally
            {
                if (originalSynchronizationContext != null)
                {
                    SynchronizationContext.SetSynchronizationContext(originalSynchronizationContext);

                    if (TD.SynchronizationContextResetIsEnabled())
                    {
                        TD.SynchronizationContextReset(originalSynchronizationContext.GetType().ToString());
                    }
                }
            }

            if (TD.FindInitiatedInDiscoveryClientChannelIsEnabled())
            {
                TD.FindInitiatedInDiscoveryClientChannel();
            }
        }
        public ResolveAsyncResult(ResolveCriteria resolveCriteria, DiscoveryEndpoint forwardingDiscoveryEndpoint, AsyncCallback callback, object state)
            : base(callback, state)
        {
            this.resolveCriteria = resolveCriteria;

            this.discoveryClient = new DiscoveryClient(forwardingDiscoveryEndpoint);
            this.discoveryClient.ResolveCompleted += new EventHandler<ResolveCompletedEventArgs>(ResolveCompleted);

            // Forwards the Resolve request message
            this.discoveryClient.ResolveAsync(resolveCriteria);
        }
Example #15
0
	static void UseCase1Core (Uri serviceUri, DiscoveryEndpoint dEndpoint)
	{
		// actual client, with DiscoveryClientBindingElement
		var be = new DiscoveryClientBindingElement () { DiscoveryEndpointProvider = new ManagedDiscoveryEndpointProvider (dEndpoint) };
		var clientBinding = new CustomBinding (new BasicHttpBinding ());
		clientBinding.Elements.Insert (0, be);
		clientBinding.SendTimeout = TimeSpan.FromSeconds (10);
		clientBinding.ReceiveTimeout = TimeSpan.FromSeconds (10);
		var cf = new ChannelFactory<ITestService> (clientBinding, DiscoveryClientBindingElement.DiscoveryEndpointAddress);
		var ch = cf.CreateChannel ();
		Console.WriteLine (ch.Echo ("TEST"));
	}
Example #16
0
		private void DiscoveryEndpointFaulted(object sender, DiscoveryEndpointFaultEventArgs args)
		{
			using (var locker = @lock.ForReadingUpgradeable())
			{
				if (args.Culprit != endpoint)
					return;

				locker.Upgrade();

				endpoint = null;
			}
		}
Example #17
0
	static void UseCase1Core (Uri serviceUri, AnnouncementEndpoint aEndpoint, DiscoveryEndpoint dEndpoint)
	{
		var host = new ServiceHost (typeof (TestService));
		var sdb = new ServiceDiscoveryBehavior ();
		sdb.AnnouncementEndpoints.Add (aEndpoint);
		host.Description.Behaviors.Add (sdb);
		host.AddServiceEndpoint (typeof (ITestService), new BasicHttpBinding (), serviceUri);
		host.Open ();
		Console.WriteLine ("Type [CR] to quit ...");
		Console.ReadLine ();
		host.Close ();
	}
Example #18
0
		public DiscoveryClient (DiscoveryEndpoint discoveryEndpoint)
		{
			if (discoveryEndpoint == null)
				throw new ArgumentNullException ("discoveryEndpoint");

			// create DiscoveryTargetClientXX for each version:
			// Managed -> DiscoveryTargetClientType (request-reply)
			// Adhoc   -> DiscoveryProxyClientType (duplex)
			if (discoveryEndpoint.DiscoveryMode == ServiceDiscoveryMode.Managed)
				client = Activator.CreateInstance (discoveryEndpoint.DiscoveryVersion.DiscoveryProxyClientType, new object [] {discoveryEndpoint});
			else
				client = Activator.CreateInstance (discoveryEndpoint.DiscoveryVersion.DiscoveryTargetClientType, new object [] {discoveryEndpoint});
		}
Example #19
0
	static void RunCodeUnderDiscoveryHost (Uri serviceUri, Uri aHostUri)
	{
		// announcement service
		var abinding = new CustomBinding (new HttpTransportBindingElement ());
		var aAddress = new EndpointAddress (aHostUri);
		var aEndpoint = new AnnouncementEndpoint (abinding, aAddress);
		
		// discovery service
		var dBinding = new CustomBinding (new TextMessageEncodingBindingElement (), new TcpTransportBindingElement ());
		var dEndpoint = new DiscoveryEndpoint (DiscoveryVersion.WSDiscovery11, ServiceDiscoveryMode.Adhoc, dBinding, new EndpointAddress ("net.tcp://" + hostname + ":9090/"));
		// Without this, .NET rejects the host as if it had no service.
		dEndpoint.IsSystemEndpoint = false;
		var ib = new InspectionBehavior ();
		ib.ReplySending += delegate (ref Message msg, object o) {
			var mb = msg.CreateBufferedCopy (0x10000);
			msg = mb.CreateMessage ();
			Console.Error.WriteLine (mb.CreateMessage ());
			};
		ib.RequestReceived += delegate (ref Message msg, IClientChannel channel, InstanceContext instanceContext) {
			var mb = msg.CreateBufferedCopy (0x10000);
			msg = mb.CreateMessage ();
			Console.Error.WriteLine (mb.CreateMessage ());
			return null;
			};
		ib.ReplyReceived += delegate (ref Message msg, object o) {
			var mb = msg.CreateBufferedCopy (0x10000);
			msg = mb.CreateMessage ();
			Console.Error.WriteLine (mb.CreateMessage ());
			};
		ib.RequestSending += delegate (ref Message msg, IClientChannel channel) {
			var mb = msg.CreateBufferedCopy (0x10000);
			msg = mb.CreateMessage ();
			Console.Error.WriteLine (mb.CreateMessage ());
			return null;
			};

		dEndpoint.Behaviors.Add (ib);
		aEndpoint.Behaviors.Add (ib);

		// it internally hosts an AnnouncementService
		using (var inst = new AnnouncementBoundDiscoveryService (aEndpoint)) {
			var host = new ServiceHost (inst);
			host.AddServiceEndpoint (dEndpoint);
			host.Description.Behaviors.Find<ServiceDebugBehavior> ()
				.IncludeExceptionDetailInFaults = true;
			host.Open ();
			Console.WriteLine ("Type [CR] to quit...");
			Console.ReadLine ();
			host.Close ();
		}
	}
Example #20
0
        public FindAsyncResult(FindRequestContext findRequestContext, DiscoveryEndpoint forwardingDiscoveryEndpoint, AsyncCallback callback, object state)
            : base(callback, state)
        {
            // Store the context. Responses will be added to this context
            this.findRequestContext = findRequestContext;

            // Attach delegates which will handle the find responses
            this.discoveryClient = new DiscoveryClient(forwardingDiscoveryEndpoint);
            this.discoveryClient.FindProgressChanged += new EventHandler<FindProgressChangedEventArgs>(FindProgressChanged);
            this.discoveryClient.FindCompleted += new EventHandler<FindCompletedEventArgs>(FindCompleted);

            // Forward the Probe request message
            this.discoveryClient.FindAsync(findRequestContext.Criteria);
        }        
Example #21
0
		// copied from UdpDiscoveryEndpointTest.
		public void TestDiscoveryEndpoint (DiscoveryEndpoint de)
		{
			Assert.AreEqual (DiscoveryVersion.WSDiscovery11, de.DiscoveryVersion, "#1");
			Assert.AreEqual (ServiceDiscoveryMode.Adhoc, de.DiscoveryMode, "#2");
			Assert.AreEqual (TimeSpan.FromMilliseconds (500), de.MaxResponseDelay, "#3");
			var cd = de.Contract;
			Assert.IsNotNull (cd, "#11");
			Assert.IsNotNull (de.Binding, "#12");
			TransportBindingElement tbe;
			Assert.IsTrue (de.Binding.CreateBindingElements ().Any (be => (tbe = be as TransportBindingElement) != null && tbe.Scheme == "soap.udp"), "#12-2");
			Assert.IsNotNull (de.Address, "#13");
			Assert.AreEqual (DiscoveryVersion.WSDiscovery11.AdhocAddress, de.Address.Uri, "#13-2");
			Assert.AreEqual (Socket.SupportsIPv4 ? UdpDiscoveryEndpoint.DefaultIPv4MulticastAddress : UdpDiscoveryEndpoint.DefaultIPv6MulticastAddress, de.ListenUri, "#14");
		}
Example #22
0
		public override DiscoveryEndpoint GetDiscoveryEndpoint()
		{
			using (var locker = @lock.ForReadingUpgradeable())
			{
				if (endpoint != null)
					return endpoint;

				locker.Upgrade();

				if (endpoint == null)
					endpoint = inner.GetDiscoveryEndpoint();

				return endpoint;
			}
		}
Example #23
0
		public void DefaultValues ()
		{
			var de = new DiscoveryEndpoint ();
			Assert.AreEqual (DiscoveryVersion.WSDiscovery11, de.DiscoveryVersion, "#1");
			Assert.AreEqual (ServiceDiscoveryMode.Managed, de.DiscoveryMode, "#2");
			Assert.AreEqual (TimeSpan.Zero, de.MaxResponseDelay, "#3");
			var cd = de.Contract;
			Assert.IsNotNull (cd, "#11"); // some version-dependent internal type.
			Assert.AreEqual ("http://docs.oasis-open.org/ws-dd/ns/discovery/2009/01", cd.Namespace, "#11-2");
			Assert.AreEqual ("DiscoveryProxy", cd.Name, "#11-3");
			Assert.AreEqual (2, cd.Operations.Count, "#11-4");
			Assert.IsTrue (cd.Operations.Any (od => !od.IsOneWay && od.Messages.Any (md => md.Action == "http://docs.oasis-open.org/ws-dd/ns/discovery/2009/01/Probe")), "#11-5");
			Assert.IsTrue (cd.Operations.Any (od => !od.IsOneWay && od.Messages.Any (md => md.Action == "http://docs.oasis-open.org/ws-dd/ns/discovery/2009/01/Resolve")), "#11-6");
			Assert.IsNull (de.Binding, "#12");
			Assert.IsNull (de.Address, "#13");
			Assert.IsNull (de.ListenUri, "#14");
		}
Example #24
0
        public static void Main()
        {
            Uri probeEndpointAddress = new Uri("net.tcp://localhost:8001/Probe");
            Uri announcementEndpointAddress = new Uri("net.tcp://localhost:9021/Announcement");

            // Host the DiscoveryProxy service
            ServiceHost proxyServiceHost = new ServiceHost(new DiscoveryProxyService());

            try
            {
                // Add DiscoveryEndpoint to receive Probe and Resolve messages
                DiscoveryEndpoint discoveryEndpoint = new DiscoveryEndpoint(new NetTcpBinding(), new EndpointAddress(probeEndpointAddress));
                discoveryEndpoint.IsSystemEndpoint = false;

                // Add AnnouncementEndpoint to receive Hello and Bye announcement messages
                AnnouncementEndpoint announcementEndpoint = new AnnouncementEndpoint(new NetTcpBinding(), new EndpointAddress(announcementEndpointAddress));

                proxyServiceHost.AddServiceEndpoint(discoveryEndpoint);
                proxyServiceHost.AddServiceEndpoint(announcementEndpoint);

                proxyServiceHost.Open();

                Console.WriteLine("Proxy Service started.");
                Console.WriteLine();
                Console.WriteLine("Press <ENTER> to terminate the service.");
                Console.WriteLine();
                Console.ReadLine();

                proxyServiceHost.Close();
            }
            catch (CommunicationException e)
            {
                Console.WriteLine(e.Message);
            }
            catch (TimeoutException e)
            {
                Console.WriteLine(e.Message);
            }

            if (proxyServiceHost.State != CommunicationState.Closed)
            {
                Console.WriteLine("Aborting the service...");
                proxyServiceHost.Abort();
            }
        }
        public DiscoveryClient(DiscoveryEndpoint discoveryEndpoint)
        {
            if (discoveryEndpoint == null)
            {
                throw new ArgumentNullException("discoveryEndpoint");
            }

            // create DiscoveryTargetClientXX for each version:
            // Managed -> DiscoveryTargetClientType (request-reply)
            // Adhoc   -> DiscoveryProxyClientType (duplex)
            if (discoveryEndpoint.DiscoveryMode == ServiceDiscoveryMode.Managed)
            {
                client = Activator.CreateInstance(discoveryEndpoint.DiscoveryVersion.DiscoveryProxyClientType, new object [] { discoveryEndpoint });
            }
            else
            {
                client = Activator.CreateInstance(discoveryEndpoint.DiscoveryVersion.DiscoveryTargetClientType, new object [] { discoveryEndpoint });
            }
        }
Example #26
0
		public void AdhocDefaultValues ()
		{
			var de = new DiscoveryEndpoint (DiscoveryVersion.WSDiscoveryCD1, ServiceDiscoveryMode.Adhoc);
			Assert.AreEqual (DiscoveryVersion.WSDiscoveryCD1, de.DiscoveryVersion, "#1");
			Assert.AreEqual (ServiceDiscoveryMode.Adhoc, de.DiscoveryMode, "#2");
			Assert.AreEqual (TimeSpan.Zero, de.MaxResponseDelay, "#3");
			var cd = de.Contract;
			Assert.IsNotNull (cd, "#11"); // some version-dependent internal type.
			Assert.AreEqual ("http://docs.oasis-open.org/ws-dd/ns/discovery/2008/09", cd.Namespace, "#11-2");
			Assert.AreEqual ("TargetService", cd.Name, "#11-3");
			Assert.AreEqual (5, cd.Operations.Count, "#11-4");
			Assert.IsTrue (cd.Operations.Any (od => od.IsOneWay && od.Messages.Any (md => md.Action == "http://docs.oasis-open.org/ws-dd/ns/discovery/2008/09/Probe")), "#11-5");
			Assert.IsTrue (cd.Operations.Any (od => od.IsOneWay && od.Messages.Any (md => md.Action == "http://docs.oasis-open.org/ws-dd/ns/discovery/2008/09/Resolve")), "#11-6");
			Assert.IsTrue (cd.Operations.Any (od => od.IsOneWay && od.Messages.Any (md => md.Action == "http://docs.oasis-open.org/ws-dd/ns/discovery/2008/09/ProbeMatches")), "#11-7");
			Assert.IsTrue (cd.Operations.Any (od => od.IsOneWay && od.Messages.Any (md => md.Action == "http://docs.oasis-open.org/ws-dd/ns/discovery/2008/09/ResolveMatches")), "#11-8");
			Assert.IsTrue (cd.Operations.Any (od => od.IsOneWay && od.Messages.Any (md => md.Action == "http://docs.oasis-open.org/ws-dd/ns/discovery/2008/09/Hello")), "#11-9");
			Assert.IsNull (de.Binding, "#12");
			Assert.IsNull (de.Address, "#13");
			Assert.IsNull (de.ListenUri, "#14");
		}
Example #27
0
	static void RunCodeUnderDiscoveryHost (Uri serviceUri, Uri dHostUri, Action<Uri,DiscoveryEndpoint> action)
	{
		var dbinding = new CustomBinding (new HttpTransportBindingElement ());
		var dAddress = new EndpointAddress (dHostUri);
		var dEndpoint = new DiscoveryEndpoint (dbinding, dAddress);
		var ib = new InspectionBehavior ();
		ib.RequestSending += delegate (ref Message msg, IClientChannel channel) {
			var mb = msg.CreateBufferedCopy (0x10000);
			msg = mb.CreateMessage ();
			Console.WriteLine (mb.CreateMessage ());
			return null;
			};
		ib.ReplyReceived += delegate (ref Message msg, object id) {
			var mb = msg.CreateBufferedCopy (0x10000);
			msg = mb.CreateMessage ();
			Console.WriteLine (mb.CreateMessage ());
			}; 
		dEndpoint.Behaviors.Add (ib);

		action (serviceUri, dEndpoint);
	}
Example #28
0
        public static void Main()
        {
            Uri baseAddress = new Uri("net.tcp://localhost:8001/DiscoveryRouter/");            

            ServiceHost serviceHost = new ServiceHost(new DiscoveryRoutingService(new UdpDiscoveryEndpoint()), baseAddress);

            try
            {
                DiscoveryEndpoint discoveryEndpoint = new DiscoveryEndpoint(new NetTcpBinding(), new EndpointAddress("net.tcp://localhost:8001/DiscoveryRouter/"));
                discoveryEndpoint.IsSystemEndpoint = false;

                serviceHost.AddServiceEndpoint(discoveryEndpoint);

                serviceHost.Open();

                Console.WriteLine("Discovery Routing Service started at {0}", baseAddress);
                Console.WriteLine();
                Console.WriteLine("Press <ENTER> to terminate the service.");
                Console.WriteLine();
                Console.ReadLine();

                serviceHost.Close();
            }
            catch (CommunicationException e)
            {
                Console.WriteLine(e.Message);
            }
            catch (TimeoutException e)
            {
                Console.WriteLine(e.Message);
            }            

            if (serviceHost.State != CommunicationState.Closed)
            {
                Console.WriteLine("Aborting the service...");
                serviceHost.Abort();
            }
        }
Example #29
0
		void RunCodeUnderDiscoveryHost1 (Uri serviceUri, Uri dHostUri, Uri aHostUri, Action<Uri,AnnouncementEndpoint,DiscoveryEndpoint> action)
		{
			// announcement service
			var abinding = new CustomBinding (new HttpTransportBindingElement ());
			var aAddress = new EndpointAddress (aHostUri);
			var aEndpoint = new AnnouncementEndpoint (abinding, aAddress);
			
			// discovery service
			var dbinding = new CustomBinding (new HttpTransportBindingElement ());
			var dAddress = new EndpointAddress (dHostUri);
			var dEndpoint = new DiscoveryEndpoint (dbinding, dAddress);
			// Without this, .NET rejects the host as if it had no service.
			dEndpoint.IsSystemEndpoint = false;

			// it internally hosts an AnnouncementService
			using (var inst = new AnnouncementBoundDiscoveryService (aEndpoint)) {
				var host = new ServiceHost (inst);
				host.AddServiceEndpoint (dEndpoint);
				try {
					host.Open ();
					action (serviceUri, aEndpoint, dEndpoint);
				} finally {
					host.Close ();
				}
			}
		}
Example #30
0
			public SimpleDiscoveryEndpointProvider (DiscoveryEndpoint endpoint)
			{
				this.endpoint = endpoint;
			}
		private void DiscoverEndpoint(DiscoveryEndpoint discoveryEndpoint, DiscoveredEndpointModel model)
		{
			using (var discover = new DiscoveryClient(discoveryEndpoint))
			{
				var criteria = CreateSearchCriteria(model);

				var discovered = discover.Find(criteria);
				if (discovered.Endpoints.Count > 0)
				{
					var binding = model.Binding;
					var endpointMetadata = discovered.Endpoints[0];
					if (discovered.Endpoints.Count > 1 && model.EndpointPreference != null)
					{
						endpointMetadata = model.EndpointPreference(discovered.Endpoints);
						if (endpointMetadata == null)
						{
							throw new EndpointNotFoundException(string.Format(
								"More than one endpoint was discovered for contract {0}.  " +
								"However, an endpoint could be selected.  This is most likely " +
								"a bug with the user-defined endpoint prefeence.",
								contract.FullName));
						}
					}

					if (binding == null && model.DeriveBinding == false)
					{
						binding = GetBindingFromMetadata(endpointMetadata);
					}
					
					var address = endpointMetadata.Address;
					if (model.Identity != null)
					{
						address = new EndpointAddress(address.Uri, model.Identity, address.Headers);
					}

					binding = GetEffectiveBinding(binding, address.Uri);
					var innerCreator = GetChannel(contract, binding, address);
					channelCreator = () =>
					{
						var channel = (IChannel)innerCreator();
						if (channel is IContextChannel)
						{
							var metadata = new DiscoveredEndpointMetadata(endpointMetadata);
							((IContextChannel)channel).Extensions.Add(metadata);
						}
						return channel;
					};
				}
				else
				{
					throw new EndpointNotFoundException(string.Format(
						"Unable to discover the endpoint for contract {0}.  " + 
						"Either no service exists or it does not support discovery.",
						contract.FullName));
				}
			}
		}
Example #32
0
 internal DiscoveryOperationContextExtension(DiscoveryEndpoint endpoint)
 {
     this.endpoint = endpoint;
 }
Example #33
0
			public ManagedDiscoveryEndpointProvider (DiscoveryEndpoint endpoint)
			{
				this.endpoint = endpoint;
			}
 public SimpleDiscoveryEndpointProvider(DiscoveryEndpoint value)
 {
     this.value = value;
 }