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;
            }
        }
Example #2
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 #3
0
		public EndpointAddress DiscoverMaster()
		{
			DiscoveryClient discoveryClient = new DiscoveryClient(new UdpDiscoveryEndpoint());
			var orationiServices = discoveryClient.Find(new FindCriteria(typeof(IOrationiMasterService)));
			discoveryClient.Close();
			return orationiServices.Endpoints.Count == 0 ? null : orationiServices.Endpoints[0].Address;
		}
        // ** DISCOVERY ** //
        static bool FindService()
        {
            try
            {
                DiscoveryClient discoveryClient =
                    new DiscoveryClient(new UdpDiscoveryEndpoint(DiscoveryVersion.WSDiscovery11));

                Collection<EndpointDiscoveryMetadata> services = discoveryClient.Find(new FindCriteria(typeof(IServiceHelloWCF))).Endpoints;

                discoveryClient.Close();

                if (services.Count == 0)
                {
                    return false;
                }
                else
                {
                    serviceAddress = services[0].ListenUris[0];
                }
            }
            catch
            {
                return false;
            }

            return true;
        }
        public static void OldMain(string[] args)
        {
            var endPoint = new UdpDiscoveryEndpoint(DiscoveryVersion.WSDiscoveryApril2005);

            //not sure what this does - if anything.
            //endPoint.Binding.CreateBindingElements().Insert(0, new MulticastCapabilitiesBindingElement(true));

            var discoveryClient = new System.ServiceModel.Discovery.DiscoveryClient(endPoint);

            discoveryClient.FindProgressChanged += DiscoveryClient_FindProgressChanged;

            var findCriteria = new FindCriteria
            {
                Duration   = TimeSpan.FromSeconds(10), // Onvif device manager finds cameras almost instantly - so 10s should be plenty
                MaxResults = int.MaxValue
            };

            //Taking cue from sniffing Onvif DM UDP packets - only add one contract type filter
            findCriteria.ContractTypeNames.Add(new XmlQualifiedName("NetworkVideoTransmitter", @"http://www.onvif.org/ver10/network/wsdl"));
            //findCriteria.ContractTypeNames.Add(new XmlQualifiedName("Device", @"http://www.onvif.org/ver10/device/wsdl"));

            Console.WriteLine("Initiating find operation.");

            //discoveryClient.FindAsync(findCriteria);
            //Console.WriteLine("Returned from Async find operation");

            var response = discoveryClient.Find(findCriteria);

            Console.WriteLine($"Operation returned - Found {response.Endpoints.Count} endpoints.");

            Console.ReadKey();
        }
Example #6
0
        // ** DISCOVERY ** //
        static bool FindService()
        {
            try
            {
                DiscoveryClient discoveryClient =
                    new DiscoveryClient(new UdpDiscoveryEndpoint(DiscoveryVersion.WSDiscovery11));

                // Uncomment to support WSDiscoveryApril2005 discovery (and change app.config for binding change)
                //DiscoveryClient discoveryClient =
                //    new DiscoveryClient(new UdpDiscoveryEndpoint(DiscoveryVersion.WSDiscoveryApril2005)); 

                Collection<EndpointDiscoveryMetadata> services = discoveryClient.Find(new FindCriteria(typeof(IServiceHelloWCF))).Endpoints;

                discoveryClient.Close();

                if (services.Count == 0)
                {
                    return false;
                }
                else
                {
                    serviceAddress = services[0].ListenUris[0];
                }
            }
            catch
            {
                return false;
            }

            return true;
        }
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
        public static void Main()
        {
            // Create DiscoveryClient
            DiscoveryClient discoveryClient = new DiscoveryClient(new UdpDiscoveryEndpoint());

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

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

            FindResponse findResponse = discoveryClient.Find(findCriteria);

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

            // Check to see if endpoints were found & print the XML metadata in them.
            if (findResponse.Endpoints.Count > 0)
            {
                foreach (XElement xElement in findResponse.Endpoints[0].Extensions)
                {
                    Console.WriteLine("Printing Metadata from ServiceEndpoint:");
                    Console.WriteLine("Endpoint Information: " + xElement.Element("Information").Value);
                    Console.WriteLine("Endpoint Started at Time: " + xElement.Element("Time").Value);
                    Console.WriteLine();
                }
                InvokeCalculatorService(findResponse.Endpoints[0].Address);
            }
            Console.WriteLine("Press <ENTER> to exit.");
            Console.ReadLine();
        }
Example #9
0
        static EndpointAddress FindCalculatorServiceAddress()
        {
            // Create a discovery client using the secure endpoint that applies and checks the compact signature
            DiscoveryClient discoveryClient = new DiscoveryClient("udpSecureDiscoveryEndpoint");

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

            FindCriteria findCriteria = new FindCriteria(typeof(ICalculatorService));
            findCriteria.Duration = TimeSpan.FromSeconds(5);

            // Find ICalculatorService endpoints
            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;
            }
        }
Example #10
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 #11
0
        public static LobbyWindow lanGame(UserAccount account, ILobbyGUI gui)
        {
            DiscoveryClient dc = new DiscoveryClient(new UdpDiscoveryEndpoint());
            FindCriteria fc = new FindCriteria(typeof(IDiscoveryTest));
            fc.Duration = TimeSpan.FromSeconds(5);
            FindResponse fr = dc.Find(fc);

            if (fr.Endpoints.Count > 0)
            {
                ip = fr.Endpoints[0].Address.Uri.Host.ToString();
            }
            else
            {
                string HostName = System.Net.Dns.GetHostName();
                System.Net.IPHostEntry hostInfo = System.Net.Dns.GetHostByName(HostName);
                string IpAdresse = hostInfo.AddressList[0].ToString();
                ip = IpAdresse;
                Server server = new Server(new WCFTCPServiceFactory(),ip);
                server.run();
            }

            factory = new WCFTCPConnectionFactory();
            lobbyWindow = new LobbyWindow(account, gui, factory);
            factory.connectToLobby(ip, lobbyWindow);

            return lobbyWindow;
        }
Example #12
0
        public static MediaDevice[] GetAvailableMediaDevices()
        {
            DiscoveryClient discoveryClient = new DiscoveryClient(new UdpDiscoveryEndpoint(DiscoveryVersion.WSDiscoveryApril2005));
            FindCriteria findCriteria = new FindCriteria
            {
                Duration = TimeSpan.FromSeconds(1),
                MaxResults = 15
            };

            findCriteria.ContractTypeNames.Add(new XmlQualifiedName("NetworkVideoTransmitter", @"http://www.onvif.org/ver10/network/wsdl"));

            FindResponse findResponse = discoveryClient.Find(findCriteria);

            List<MediaDevice> cameras = new List<MediaDevice>();

            foreach (var point in findResponse.Endpoints)
            {
                Uri uri = point.ListenUris.FirstOrDefault(u => u.HostNameType == UriHostNameType.IPv4);
                if (uri != null)
                {
                    string name = ONVIFAgent.GetDeviceInformation(uri);

                    cameras.Add(new MediaDevice(name, uri));
                }
            }
            return cameras.ToArray();
        }
Example #13
0
      public static void Main(string[] args)
      {
          var endPoint        = new UdpDiscoveryEndpoint(DiscoveryVersion.WSDiscoveryApril2005);
          var discoveryClient = new System.ServiceModel.Discovery.DiscoveryClient(endPoint);

          var findCriteria = new FindCriteria
          {
              Duration   = TimeSpan.FromSeconds(3),
              MaxResults = int.MaxValue
          };

          findCriteria.ContractTypeNames.Add(new XmlQualifiedName("NetworkVideoTransmitter", @"http://www.onvif.org/ver10/network/wsdl"));

          Console.WriteLine("Initiating find operation.");

          var           response = discoveryClient.Find(findCriteria);
          List <string> lst      = new List <string>();

          foreach (var e in response.Endpoints)
          {
              foreach (var item in e.ListenUris)
              {
                  string uri  = item.OriginalString;
                  string host = item.Host;
                  lst.Add(host + ": " + uri);
              }
          }
          lst = lst.Distinct().ToList();
          lst.ForEach(x => Console.WriteLine(x));

          Console.WriteLine($"Operation returned - Found {lst.Count} endpoints.");
          Console.ReadKey();
      }
		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;
			}
		}
Example #15
0
        static EndpointAddress FindCalculatorServiceAddress()
        {
            // Create DiscoveryClient
            DiscoveryClient discoveryClient = new DiscoveryClient(new UdpDiscoveryEndpoint());

            // Find ICalculatorService endpoints in the specified scope            
            Uri scope = new Uri("ldap:///ou=engineering,o=exampleorg,c=us");
            FindCriteria findCriteria = new FindCriteria(typeof(ICalculatorService));
            findCriteria.Scopes.Add(scope);
            findCriteria.MaxResults = 1;

            Console.WriteLine("Finding ICalculatorService endpoints within {0} scope...", scope);
            Console.WriteLine();
            
            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;
            }
        }
Example #16
0
        public static EndpointAddress DiscoverAddress()
        {
            Console.WriteLine("Discovery stated at " + DateTime.Now);

            // Create DiscoveryClient
            DiscoveryClient discoveryClient = new DiscoveryClient(new UdpDiscoveryEndpoint());

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

            Console.WriteLine("Discovery finished at " + DateTime.Now);

            if (findResponse.Endpoints.Count> 0)
            {
                foreach (var e in findResponse.Endpoints)
                {
                    Console.WriteLine(e.Address + ", ContractTypeNames:" + e.ContractTypeNames
                        + ", Scopes:" + e.Scopes + ", ListenUris:" + e.ListenUris);
                }

                return findResponse.Endpoints[0].Address;

            }
            else
            {
                Console.WriteLine("No service found.");
                return null;
            }
        }
Example #17
0
 public EndpointAddress FindNotifierServiceAddress(int secondsTimeout)
 {
     DiscoveryClient discoveryClient = new DiscoveryClient(new UdpDiscoveryEndpoint());
     FindCriteria criteria = new FindCriteria(typeof(INotifierService)) { Duration = new TimeSpan(0, 0, 0, secondsTimeout) };
     FindResponse findResponse = discoveryClient.Find(criteria);
     if (findResponse.Endpoints.Count > 0)
     {
         return findResponse.Endpoints[0].Address;
     }
     return null;
 }
        /// <summary>
        /// Returns list of addresses of sync service in network.
        /// </summary>
        /// <returns>List of addresses.</returns>
        public static IEnumerable<EndpointAddress> GetAddressesOfService()
        {
            var discoverclient = new DiscoveryClient(new UdpDiscoveryEndpoint());

            FindResponse response = discoverclient.Find(new FindCriteria(typeof (ISyncService)));
            discoverclient.Close();

            return
                response.Endpoints.Where(e => e.Address.ToString().ToUpper()
                                            != Constants.LocalSyncServiceEndpointAddress.ToUpper())
                                  .Select(e => e.Address);
        }
Example #19
0
        static EndpointAddress FindCalculatorServiceAddress()
        {
            DiscoveryClient discoveryClient = new DiscoveryClient(new UdpDiscoveryEndpoint());
            FindResponse findResponse = discoveryClient.Find(new FindCriteria(typeof(ICalculator)));

            if (findResponse.Endpoints.Count > 0)
            {
                return findResponse.Endpoints[0].Address;
            }
            else
            {
                return null;
            }
        }
Example #20
0
        public void Find_Service_Publisher_Ok()
        {
            DiscoveryClient discoveryClient =
                new DiscoveryClient(new UdpDiscoveryEndpoint());

            var publisherServices =
                discoveryClient.Find(new FindCriteria(typeof(IPublisher)));

            discoveryClient.Close();

            Assert.False(publisherServices.Endpoints.Count == 0);
            var serviceAddress = publisherServices.Endpoints[0].Address;
            Assert.IsNotNull(serviceAddress);
        }
        public static ObservableCollection<EndpointAddress> ServicesAddressList()
        {
            var discoveryClient =
                new DiscoveryClient(new UdpDiscoveryEndpoint());

            var viewerServices =
                discoveryClient.Find(new FindCriteria(typeof(IRemoteService)));

            discoveryClient.Close();

            var findServiceList =
                new ObservableCollection<EndpointAddress>(viewerServices.Endpoints.Select(endpoint => endpoint.Address).ToList());

            return findServiceList;
        }
        public static IList<EndpointDiscoveryMetadata> SearchServices()
        {
            DiscoveryClient discoveryClient = new DiscoveryClient(new UdpDiscoveryEndpoint());
            try
            {
                FindResponse discoveryResponse = discoveryClient.Find(new FindCriteria(typeof(IComplexNetworkWorkerService)));
                endpoints = discoveryResponse.Endpoints;
            }
            catch (Exception)
            {
                endpoints = new List<EndpointDiscoveryMetadata>();

            }

            return endpoints;
        }
Example #23
0
 public static Uri WcfTestClient_DiscoverChannel()
 {
     var dc = new DiscoveryClient(new UdpDiscoveryEndpoint());
     FindCriteria fc = new FindCriteria(typeof(IWcfPingTest));
     fc.Duration = TimeSpan.FromSeconds(20);
     FindResponse fr = dc.Find(fc);
     foreach (EndpointDiscoveryMetadata edm in fr.Endpoints)
     {
         Console.WriteLine("uri found = " + edm.Address.Uri.ToString());
     }
     // here is the really nasty part
     // i am just returning the first channel, but it may not work.
     // you have to do some logic to decide which uri to use from the discovered uris
     // for example, you may discover "127.0.0.1", but that one is obviously useless.
     // also, catch exceptions when no endpoints are found and try again.
     return fr.Endpoints[0].Address.Uri;
 }
Example #24
0
        // ** DISCOVERY ** //
        public List<EndpointAddress> FindService()
        {
            List<EndpointAddress> service = new List<EndpointAddress>();

            DiscoveryClient discoveryClient =
                new DiscoveryClient(new UdpDiscoveryEndpoint());

            Collection<EndpointDiscoveryMetadata> publishService =
                discoveryClient.Find(new FindCriteria(typeof(IServerManagement))).Endpoints;

            discoveryClient.Close();

            foreach (var server in publishService)
            {
                service.Add(server.Address);
            }
            return service;
        }
Example #25
0
        public void TestMethod1()
        {
            var disco = new DiscoveryClient(new UdpDiscoveryEndpoint());
            var response = disco.Find(
                new FindCriteria(typeof(IMagicOracle))
                {
                    Duration = TimeSpan.FromSeconds(2)
                });

            Assert.AreNotEqual(0, response.Endpoints.Count);

            client = ChannelFactory<IMagicOracle>.CreateChannel(
                new NetNamedPipeBinding(),
                response.Endpoints[0].Address);

            var result = client.Answer("Hoe laat is het?");
            Console.WriteLine(result);
        }
Example #26
0
        static void Main(string[] args)
        {
            DiscoveryClient discoveryClient = new DiscoveryClient(new UdpDiscoveryEndpoint());
            FindCriteria criteria = new FindCriteria(typeof(ICalculator));
            criteria.Scopes.Add(new Uri("http://www.artech.com/"));
            FindResponse response = discoveryClient.Find(criteria);

            if (response.Endpoints.Count > 0)
            {
                EndpointAddress address = response.Endpoints[0].Address;
                using (ChannelFactory<ICalculator> channelFactory = new ChannelFactory<ICalculator>(new WS2007HttpBinding(), address))
                {
                    ICalculator calculator = channelFactory.CreateChannel();
                    Console.WriteLine("x + y = {2} when x = {0} and y = {1}", 1, 2, calculator.Add(1, 2));
                }
            }
            Console.Read();
        }
Example #27
0
 static bool FindService()
 {
     Console.WriteLine("\nFinding Myservice Service ..");
     DiscoveryClient discoveryClient =
           new DiscoveryClient(new UdpDiscoveryEndpoint());
     var Services =
          discoveryClient.Find(new FindCriteria(typeof(Service.IService1)));
     discoveryClient.Close();
     if (Services == null)
     {
         Console.WriteLine("\nNo services are found.");
         return false;
     }
     else
     {
         serviceAddress = Services.Endpoints[0].Address;
         return true;
     }
 }
Example #28
0
        protected override void Execute(CodeActivityContext context)
        {
            DiscoveryClient discoveryClient = new DiscoveryClient(new UdpDiscoveryEndpoint());

            FindCriteria findCriteria = new FindCriteria();
            // Create a contract to add to the findCriteria. The search will be based on this contract.
            findCriteria.ContractTypeNames.Add(new XmlQualifiedName("IPrintService", "http://tempuri.org/"));
            findCriteria.MaxResults = 1;
            findCriteria.Duration = new TimeSpan(0, 0, 0, 3);

            FindResponse findResponse = discoveryClient.Find(findCriteria);
            discoveryClient.Close();

            if (findResponse.Endpoints.Count == 0)
            {
                throw new EndpointNotFoundException("Client was unable to find any matching endpoints using Discovery.");
            }

            this.DiscoveredEndpointUri.Set(context, findResponse.Endpoints[0].Address.Uri);
        }
Example #29
0
        static void Main(string[] args)
        {
            var discovery = new DiscoveryClient(
                new UdpDiscoveryEndpoint());
            var criteria = new FindCriteria(typeof(EchoService))
            {
                Duration = TimeSpan.FromSeconds(2)
            };
            var service = discovery.Find(criteria);
            foreach (var endpoint in service.Endpoints)
            {
                Console.WriteLine("{0}", endpoint.Address);
            }

            var channelFactory =
                new ChannelFactory<EchoService>(
                    new BasicHttpBinding(),
                    service.Endpoints.FirstOrDefault().Address);
            var response = channelFactory.CreateChannel().Echo("hello!");
            Console.WriteLine(response);
        }
Example #30
0
		public override DiscoveryEndpoint GetDiscoveryEndpoint()
		{
			var forContract = DiscoveryVersion != null
				? new DiscoveryEndpoint(DiscoveryVersion, ServiceDiscoveryMode.Managed)
				: new DiscoveryEndpoint();

			using (var discover = new DiscoveryClient(GetUdpDiscoveryEndpoint()))
			{
				var criteria = GetSearchCriteria(forContract.Contract.ContractType);
				RestrictDomain(criteria);

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

			return null;
		}
Example #31
0
        public static void Main()
        {
            // Create DiscoveryClient
            DiscoveryClient discoveryClient = new DiscoveryClient(new UdpDiscoveryEndpoint());

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

            FindCriteria findCriteria = new FindCriteria(typeof(ICalculatorService));
            findCriteria.Duration = TimeSpan.FromSeconds(5);

            // Find ICalculatorService endpoints            
            FindResponse findResponse = discoveryClient.Find(findCriteria);

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

            // Check to see if endpoints were found
            if (findResponse.Endpoints.Count > 0)
            {
                EndpointDiscoveryMetadata discoveredEndpoint = findResponse.Endpoints[0];

                // Check to see if the endpoint has a listenUri and if it differs from the Address URI
                if (discoveredEndpoint.ListenUris.Count > 0 && discoveredEndpoint.Address.Uri != discoveredEndpoint.ListenUris[0])
                {
                    // Since the service is using a unique ListenUri, it needs to be invoked at the correct ListenUri 
                    InvokeCalculatorService(discoveredEndpoint.Address, discoveredEndpoint.ListenUris[0]);
                }
                else
                {
                    // Endpoint was found, however it doesn't have a unique ListenUri, hence invoke the service with only the Address URI
                    InvokeCalculatorService(discoveredEndpoint.Address, null);
                }
            }

            Console.WriteLine("Press <ENTER> to exit.");
            Console.ReadLine();
        }
Example #32
0
        public static void Main(string[] args)
        {
            var endPoint = new UdpDiscoveryEndpoint(DiscoveryVersion.WSDiscoveryApril2005);

            var discoveryClient = new System.ServiceModel.Discovery.DiscoveryClient(endPoint);

            discoveryClient.FindProgressChanged += DiscoveryClient_FindProgressChanged;

            var findCriteria = new FindCriteria
            {
                Duration   = TimeSpan.FromSeconds(10),
                MaxResults = int.MaxValue
            };

            findCriteria.ContractTypeNames.Add(new XmlQualifiedName("NetworkVideoTransmitter", @"http://www.onvif.org/ver10/network/wsdl"));

            Console.WriteLine("Initiating find operation.");
            var response = discoveryClient.Find(findCriteria);

            Console.WriteLine($"Operation returned - Found {response.Endpoints.Count} endpoints.");

            Console.ReadKey();
        }
		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));
				}
			}
		}