示例#1
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();
      }
示例#2
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 dEndpoint = new UdpDiscoveryEndpoint(DiscoveryVersion.WSDiscovery11, new Uri("soap.udp://239.255.255.250:3802/"));

        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);
    }
示例#3
0
文件: Discovery.cs 项目: zmaples/iSpy
        private static DiscoveryClient BuildDiscoveryClient(string adapterId, DiscoveryVersion version)
        {
            var epDiscovery = new UdpDiscoveryEndpoint(version);
            var b           = (CustomBinding)epDiscovery.Binding;

            if (b == null)
            {
                return(null);
            }

            epDiscovery.TransportSettings.MulticastInterfaceId = adapterId;
            b.Elements.Insert(0, new MulticastCapabilitiesBindingElement(true));

            var discoveryClient = new DiscoveryClient(epDiscovery);

            discoveryClient.FindProgressChanged += DiscoveryClientFindProgressChanged;
            //discoveryClient.FindCompleted += DiscoveryClientFindCompleted;

            FindCriteria findCriteria = new FindCriteria
            {
                Duration   = TimeSpan.FromMinutes(5),
                MaxResults = int.MaxValue
            };

            foreach (var ctn in CtNs)
            {
                findCriteria.ContractTypeNames.Add(ctn);
            }

            discoveryClient.FindAsync(findCriteria);
            return(discoveryClient);
        }
示例#4
0
        void RunCodeUnderDiscoveryHost3(Uri serviceUri, 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 dEndpoint = new UdpDiscoveryEndpoint(DiscoveryVersion.WSDiscovery11, new Uri("soap.udp://239.255.255.250:3802/"));

            // 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();
                }
            }
        }
示例#5
0
        public DiscoveryClient startDiscovery(TimeSpan span)
        {
            try
            {
                var endPoint = new UdpDiscoveryEndpoint(DiscoveryVersion.WSDiscoveryApril2005);

                var discoveryClient = new DiscoveryClient(endPoint);

                discoveryClient.FindCompleted       += DiscoveryClient_FindCompleted;
                discoveryClient.FindProgressChanged += discoveryClient_FindProgressChanged;

                FindCriteria findCriteria = new FindCriteria();
                findCriteria.Duration   = span;
                findCriteria.MaxResults = int.MaxValue;
                findCriteria.ContractTypeNames.Add(new System.Xml.XmlQualifiedName("NetworkVideoTransmitter", "http://www.onvif.org/ver10/network/wsdl"));
                discoveryClient.FindAsync(findCriteria);

                this.OnRecoveryChange("", DiscoveryEvent.EventTypes.startEvent);

                System.Diagnostics.Trace.WriteLine("DiscoveryClient.startDiscovery O.K ...");

                return(discoveryClient);
            }
            catch (Exception ex)
            {
                System.Diagnostics.Trace.WriteLine("DiscoveryServer.startDiscovery: " + ex.Message);
                return(null);
            }
        }
示例#6
0
        private void IPCameraList()
        {
            var endPoint        = new UdpDiscoveryEndpoint(DiscoveryVersion.WSDiscoveryApril2005);
            var discoveryClient = new 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"));

            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);
                }
            }
            lst = lst.Distinct().ToList();
            lst.ForEach(x => cmbCameraDevices.Items.Add(x));
        }
        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();
        }
示例#8
0
        protected internal override ServiceEndpoint CreateServiceEndpoint(ContractDescription contractDescription)
        {
            if (contractDescription == null)
            {
                throw new ArgumentNullException("contractDescription");
            }
            DiscoveryVersion ver = null;

            switch (contractDescription.ContractType.Namespace)
            {
            case DiscoveryVersion.Namespace11:
                ver = DiscoveryVersion.WSDiscovery11;
                break;

            case DiscoveryVersion.NamespaceApril2005:
                ver = DiscoveryVersion.WSDiscoveryApril2005;
                break;

            case DiscoveryVersion.NamespaceCD1:
                ver = DiscoveryVersion.WSDiscoveryCD1;
                break;
            }
            var ret = new UdpDiscoveryEndpoint(ver, MulticastAddress);

            ret.MaxResponseDelay = MaxResponseDelay;
            TransportSettings.ApplyConfiguration(ret.TransportSettings);
            return(ret);
        }
示例#9
0
        public void DefaultSettings()
        {
            var binding = new UdpDiscoveryEndpoint().Binding;

            Assert.AreEqual(TimeSpan.FromMinutes(1), binding.SendTimeout, "#1");
            Assert.AreEqual(TimeSpan.FromMinutes(10), binding.ReceiveTimeout, "#2");
        }
        void ApplyConfiguration(ServiceEndpoint endpoint)
        {
            UdpDiscoveryEndpoint udpDiscoveryEndpoint = (UdpDiscoveryEndpoint)endpoint;

            udpDiscoveryEndpoint.MulticastAddress = this.MulticastAddress;
#pragma warning disable 0618
            this.TransportSettings.ApplyConfiguration(udpDiscoveryEndpoint.TransportSettings);
#pragma warning restore 0618
        }
示例#11
0
        void InitializeDiscoveryClient(DiscoveryVersion version)
        {
            UdpDiscoveryEndpoint endpoint = new UdpDiscoveryEndpoint(version);

            _discoveryClient = new DiscoveryClient(endpoint);

            _discoveryClient.FindProgressChanged += DiscoveryClient_FindProgressChanged;
            _discoveryClient.FindCompleted       += DiscoveryClient_FindCompleted;
        }
示例#12
0
		public void CanBuildChannelListener ()
		{
			var binding = new UdpDiscoveryEndpoint ().Binding;
			Assert.IsFalse (binding.CanBuildChannelListener<IRequestChannel> (), "#1");
			Assert.IsFalse (binding.CanBuildChannelListener<IRequestSessionChannel> (), "#2");
			Assert.IsTrue (binding.CanBuildChannelListener<IDuplexChannel> (), "#3");
			Assert.IsFalse (binding.CanBuildChannelListener<IDuplexSessionChannel> (), "#4");
			Assert.IsFalse (binding.CanBuildChannelListener<IOutputChannel> (), "#5");
			Assert.IsFalse (binding.CanBuildChannelListener<IOutputSessionChannel> (), "#6");
		}
示例#13
0
        private void btnListen_Click(object sender, EventArgs e)
        {
            if (_serviceHost == null)
            {
                _serviceHost = new ServiceHost(typeof(SampleService), _baseAddress);

                {
                    // Add an endpoint to the service
                    ServiceEndpoint discoverableEndpoint = _serviceHost.AddServiceEndpoint(
                        typeof(ISampleService),
                        new BasicHttpBinding(),
                        "/DiscoverableEndpoint");

                    // Add Scopes to the endpoint
                    EndpointDiscoveryBehavior discoverableEndpointBehavior = new EndpointDiscoveryBehavior();

                    foreach (ListViewItem item in lvTypes.CheckedItems)
                    {
                        XmlQualifiedName type = new XmlQualifiedName(item.SubItems[0].Text, item.SubItems[1].Text);
                        discoverableEndpointBehavior.ContractTypeNames.Add(type);
                    }

                    foreach (ListViewItem item in lvScopes.CheckedItems)
                    {
                        discoverableEndpointBehavior.Scopes.Add(new Uri(item.SubItems[0].Text));
                    }

                    discoverableEndpointBehavior.Enabled = true;
                    discoverableEndpoint.Behaviors.Add(discoverableEndpointBehavior);
                }

                // without this fragment, Probe does not work
                {
                    ServiceDiscoveryBehavior sdb = new ServiceDiscoveryBehavior();
                    _serviceHost.Description.Behaviors.Add(sdb);
                    UdpDiscoveryEndpoint discoveryEndpoint = new UdpDiscoveryEndpoint(SelectedVersion);
                    discoveryEndpoint.TransportSettings.TimeToLive = 5;
                    _serviceHost.AddServiceEndpoint(discoveryEndpoint);
                    //discoveryEndpoint.Address = new EndpointAddress(new Uri("urn:uuid" + _guid.ToString()));
                }

                _serviceHost.Open();

                btnListen.Text = "Stop";
            }
            else
            {
                _serviceHost.Close();
                _serviceHost   = null;
                btnListen.Text = "Listen";
            }
        }
示例#14
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 dEndpoint = new UdpDiscoveryEndpoint(DiscoveryVersion.WSDiscovery11, new Uri("soap.udp://239.255.255.250:3802/"));

        // 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 ctx) {
            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();
        }
    }
        protected internal override void InitializeFrom(ServiceEndpoint endpoint)
        {
            base.InitializeFrom(endpoint);

            UdpDiscoveryEndpoint source = (UdpDiscoveryEndpoint)endpoint;

            this.MaxResponseDelay = source.MaxResponseDelay;
            this.DiscoveryMode    = source.DiscoveryMode;
            this.MulticastAddress = source.MulticastAddress;
#pragma warning disable 0618
            this.TransportSettings.InitializeFrom(source.TransportSettings);
#pragma warning restore 0618
        }
示例#16
0
        public HostDiscovery(Type type, TimeSpan Duration)
        {
            m_ContractType = type;

            _udpDiscoveryEndpoint = new UdpDiscoveryEndpoint();

            _lockObject = new object();

            _managedMode = EnableDiscoveryManagedModeEnum.FALSE;

            DiscoveryAdHoc();

            m_FindDuration = Duration;
        }
示例#17
0
    static void Main(string[] args)
    {
        var endPoint = new UdpDiscoveryEndpoint(DiscoveryVersion.WSDiscoveryApril2005);

        var discoveryClient = new DiscoveryClient(endPoint);

        discoveryClient.FindProgressChanged += discoveryClient_FindProgressChanged;
        FindCriteria findCriteria = new FindCriteria();

        findCriteria.Duration   = TimeSpan.MaxValue;
        findCriteria.MaxResults = int.MaxValue;
        discoveryClient.FindAsync(findCriteria);
        Console.ReadKey();
    }
示例#18
0
        public HostDiscovery(Type type)
        {
            m_ContractType = type;

            _udpDiscoveryEndpoint = new UdpDiscoveryEndpoint();

            _lockObject = new object();

            _managedMode = EnableDiscoveryManagedModeEnum.FALSE;

            DiscoveryAdHoc();

            // Change the Default Duration from 20 seconds to 5 Seconds
            m_FindDuration = new TimeSpan(0, 0, 0, 5, 0);
        }
        public static void AddDiscovery(ServiceHost host, Type serviceType)
        {
            // Add a ServiceDiscoveryBehavior
            host.Description.Behaviors.Add(new ServiceDiscoveryBehavior());

            // Add a UdpDiscoveryEndpoint
            var udpDiscoveryEndpoint = new UdpDiscoveryEndpoint();

            host.AddServiceEndpoint(udpDiscoveryEndpoint);

            // Add a discovery behavior for Meta Extensions
            EndpointDiscoveryBehavior endpointDiscoveryBehavior = new EndpointDiscoveryBehavior();

            endpointDiscoveryBehavior.Extensions.Add(GetLocalAddresses());
            host.Description.Endpoints[0].Behaviors.Add(endpointDiscoveryBehavior);
        }
    static void Main(string[] args)
    {
        var endPoint = new UdpDiscoveryEndpoint(DiscoveryVersion.WSDiscoveryApril2005);

        var discoveryClient = new DiscoveryClient(endPoint);

        discoveryClient.FindProgressChanged += discoveryClient_FindProgressChanged;
        FindCriteria findCriteria = new FindCriteria();

        findCriteria.Duration   = TimeSpan.MaxValue;
        findCriteria.MaxResults = int.MaxValue;
        // Edit: optionally specify contract type, ONVIF v1.0
        findCriteria.ContractTypeNames.Add(new XmlQualifiedName("NetworkVideoTransmitter",
                                                                "http://www.onvif.org/ver10/network/wsdl"));
        discoveryClient.FindAsync(findCriteria);
        Console.ReadKey();
    }
示例#21
0
        public void DefaultValues()
        {
            var de = new UdpDiscoveryEndpoint();

            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");
        }
示例#22
0
        public void Discover(int discoveryTimeOutMiliseconds, EventHandler <FindCompletedEventArgs> discoveryCompleted)
        {
            var          endPoint              = new UdpDiscoveryEndpoint(DiscoveryVersion.WSDiscoveryApril2005);
            FindCriteria findCriteria          = new FindCriteria();
            var          contractTypeName      = "NetworkVideoTransmitter";
            var          contractTypeNamespace = "http://www.onvif.org/ver10/network/wsdl";

            // those parametes are defined by onvif standard
            findCriteria.ContractTypeNames.Add(new XmlQualifiedName(contractTypeName, contractTypeNamespace));

            var discoveryClient = new DiscoveryClient(endPoint);

            discoveryClient.FindProgressChanged += discoveryClient_FindProgressChanged;
            discoveryClient.FindCompleted       += discoveryCompleted;

            findCriteria.Duration   = TimeSpan.FromMilliseconds(discoveryTimeOutMiliseconds);
            findCriteria.MaxResults = int.MaxValue;
            discoveryClient.FindAsync(findCriteria);
        }
示例#23
0
        private void findServiceButton_Click(object sender, EventArgs e)
        {
            tracer.Verb("ScreenCastControl::findServiceButton_Click(...)");

            //logger.Debug("findServiceButton_Click(...)");

            if (!finding)
            {
                var udpDiscoveryEndpoint = new UdpDiscoveryEndpoint();
                udpDiscoveryEndpoint.EndpointBehaviors.Add(new WcfDiscoveryAddressCustomEndpointBehavior());

                if (discoveryClient == null)
                {
                    discoveryClient = new DiscoveryClient(udpDiscoveryEndpoint);

                    discoveryClient.FindCompleted       += DiscoveryClient_FindCompleted;
                    discoveryClient.FindProgressChanged += DiscoveryClient_FindProgressChanged;
                }

                var criteria = new FindCriteria(typeof(IScreenCastService));
                criteria.Duration = TimeSpan.FromSeconds(5);


                finding = true;
                findServiceButton.Text = "_Cancel";
                labelStatus.Text       = "_Finding...";

                connectButton.Enabled    = false;
                hostsComboBox.Enabled    = false;
                hostsComboBox.DataSource = null;

                discoveryClient.FindAsync(criteria, this);
            }
            else
            {
                if (discoveryClient != null)
                {
                    discoveryClient.CancelAsync(this);
                    discoveryClient.Close();
                }
            }
        }
示例#24
0
    static void RunCodeUnderDiscoveryHost(Uri serviceUri, Uri dHostUri, Action <Uri, DiscoveryEndpoint> action)
    {
        var dEndpoint = new UdpDiscoveryEndpoint(DiscoveryVersion.WSDiscoveryApril2005, new Uri("soap.udp://239.255.255.250:3802/"));
        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);
    }
示例#25
0
        void _SearchONVIF()
        {
            var endPoint = new UdpDiscoveryEndpoint(DiscoveryVersion.WSDiscoveryApril2005);

            var discoveryClient = new DiscoveryClient(endPoint);

            discoveryClient.FindProgressChanged += discoveryClient_FindProgressChanged;

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

            // Edit: optionally specify contract type, ONVIF v1.0
            findCriteria.ContractTypeNames.Add(new XmlQualifiedName("NetworkVideoTransmitter",
                                                                    "http://www.onvif.org/ver10/network/wsdl"));

            discoveryClient.FindAsync(findCriteria);
            comboBox1.Invoke(new Action(() => { comboBox1.Items.Clear(); }));
        }
示例#26
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();
        }
示例#27
0
        static void Main(string[] args)
        {
            Console.WriteLine("Discovering devices...");
            var          endPoint              = new UdpDiscoveryEndpoint(DiscoveryVersion.WSDiscoveryApril2005);
            FindCriteria findCriteria          = new FindCriteria();
            var          contractTypeName      = "NetworkVideoTransmitter";
            var          contractTypeNamespace = "http://www.onvif.org/ver10/network/wsdl";

            // those parametes are defined by onvif standard
            findCriteria.ContractTypeNames.Add(new XmlQualifiedName(contractTypeName, contractTypeNamespace));

            var discoveryClient = new DiscoveryClient(endPoint);

            discoveryClient.FindProgressChanged += discoveryClient_FindProgressChanged;
            discoveryClient.FindCompleted       += discoveryClient_FindCompleted;


            findCriteria.Duration   = TimeSpan.MaxValue;
            findCriteria.MaxResults = int.MaxValue;
            discoveryClient.FindAsync(findCriteria);

            Console.ReadKey();
        }
示例#28
0
        public HostDiscovery(Type type, TimeSpan Duration, EnableDiscoveryManagedModeEnum ManagedMode, string DiscoveryProxyUri)
        {
            m_ContractType = type;

            _lockObject = new object();

            _managedMode = ManagedMode;

            if (ManagedMode == EnableDiscoveryManagedModeEnum.TRUE)
            {
                DiscoveryManaged(DiscoveryProxyUri);
            }
            else
            {
                _udpDiscoveryEndpoint = new UdpDiscoveryEndpoint();
                DiscoveryAdHoc();

                //if (ManagedMode == EnableDiscoveryManagedModeEnum.AUTO)
                //{
                //    m_DiscoveryClient.ProxyAvailable += new EventHandler<AnnouncementEventArgs>(m_DiscoveryClient_ProxyAvailable);
                //}
            }
            m_FindDuration = Duration;
        }
示例#29
0
        public void Start(Type contractType, int refreshInterval, int maxResults)
        {
            if (running)
            {
                Console.WriteLine("Invalid state...");
                return;
            }

            Task.Run(() =>
            {
                var udpDiscoveryEndpoint = new UdpDiscoveryEndpoint();
                udpDiscoveryEndpoint.EndpointBehaviors.Add(new WcfDiscoveryAddressCustomEndpointBehavior());

                DiscoveryClient discoveryClient = null;

                try
                {
                    discoveryClient = new DiscoveryClient(udpDiscoveryEndpoint);

                    var criteria        = new FindCriteria(contractType);
                    criteria.Duration   = TimeSpan.FromSeconds(refreshInterval);
                    criteria.MaxResults = maxResults;

                    //discoveryClient.FindAsync(criteria, this);

                    if (!running)
                    {
                        running = true;
                    }

                    while (running)
                    {
                        Console.WriteLine("discoveryClient.Find(...) BEGIN");

                        var result = discoveryClient.Find(criteria);

                        if (result != null)
                        {
                            List <ScreenCastServiceInput> inputs = new List <ScreenCastServiceInput>();

                            //var endpoints = result.Endpoints;
                            //if (endpoints == null || endpoints.Count == 0)
                            //{
                            //	Console.WriteLine("endpoints == null || endpoints.Count == 0");
                            //	continue;
                            //}


                            foreach (var ep in result.Endpoints)
                            {
                                string address  = ep.Address.ToString();
                                string hostName = address;

                                var extensions = ep.Extensions;
                                if (extensions != null && extensions.Count > 0)
                                {
                                    var hostElement = extensions.FirstOrDefault(el => el.Name == "HostName");
                                    if (hostElement != null)
                                    {
                                        hostName = hostElement.Value;                                        // + " {" + address + "}";
                                    }
                                }

                                var input = new ScreenCastServiceInput
                                {
                                    HostName = hostName,
                                    Address  = address,
                                };

                                inputs.Add(input);
                                //Console.WriteLine(hostName + " " + address);
                            }

                            InputsUpdated?.Invoke(inputs);
                        }

                        Console.WriteLine("discoveryClient.Find(...) END");
                    }
                }
                finally
                {
                    if (discoveryClient != null)
                    {
                        discoveryClient.Close();
                        discoveryClient = null;
                    }
                }
            });
        }
示例#30
0
        private void findServiceButton_Click(object sender, EventArgs e)
        {
            logger.Debug("\nFinding IRemoteDesktopService...");

            var udpDiscoveryEndpoint = new UdpDiscoveryEndpoint();

            udpDiscoveryEndpoint.EndpointBehaviors.Add(new WcfDiscoveryAddressCustomEndpointBehavior());

            DiscoveryClient discoveryClient = new DiscoveryClient(udpDiscoveryEndpoint);

            var criteria = new FindCriteria(typeof(IRemoteDesktopService));

            criteria.Duration = TimeSpan.FromSeconds(5);
            ProgressForm progress = new ProgressForm
            {
                StartPosition = FormStartPosition.CenterParent,
            };

            List <ComboBoxItem> hostItems = new List <ComboBoxItem>();

            discoveryClient.FindCompleted += (o, a) =>
            {
                logger.Debug("FindCompleted(...)");

                if (a.Cancelled)
                {
                    logger.Debug("Cancelled");
                }
                if (a.Error != null)
                {
                    logger.Debug(a.Error.ToString());
                }

                if (!a.Cancelled)
                {
                    var result = a.Result;
                    if (result != null)
                    {
                        foreach (var ep in result.Endpoints)
                        {
                            string address  = ep.Address.ToString();
                            string hostName = address;

                            var extensions = ep.Extensions;
                            if (extensions != null && extensions.Count > 0)
                            {
                                var hostElement = extensions.FirstOrDefault(el => el.Name == "HostName");
                                if (hostElement != null)
                                {
                                    hostName = hostElement.Value; // + " {" + address + "}";
                                }
                            }

                            logger.Debug(hostName);

                            hostItems.Add(new ComboBoxItem
                            {
                                Name = hostName,
                                Tag  = address,
                            });
                        }
                    }
                }

                hostsComboBox.DataSource    = hostItems;
                hostsComboBox.DisplayMember = "Name";

                progress.Close();
            };

            discoveryClient.FindProgressChanged += (o, a) =>
            {
                logger.Debug("FindProgressChanged(...) " + a.EndpointDiscoveryMetadata.Address.ToString());
            };


            progress.Shown += (o, a) =>
            {
                discoveryClient.FindAsync(criteria, this);
            };

            progress.FormClosed += (o, a) =>
            {
                logger.Debug("FormClosed(...)");

                if (discoveryClient != null)
                {
                    discoveryClient.CancelAsync(this);
                    discoveryClient.Close();
                }
            };

            progress.ShowDialog();
        }
		protected internal override ServiceEndpoint CreateServiceEndpoint (ContractDescription contractDescription)
		{
			if (contractDescription == null)
				throw new ArgumentNullException ("contractDescription");
			DiscoveryVersion ver = null;
			switch (contractDescription.ContractType.Namespace) {
			case DiscoveryVersion.Namespace11:
				ver = DiscoveryVersion.WSDiscovery11;
				break;
			case DiscoveryVersion.NamespaceApril2005:
				ver = DiscoveryVersion.WSDiscoveryApril2005;
				break;
			case DiscoveryVersion.NamespaceCD1:
				ver = DiscoveryVersion.WSDiscoveryCD1;
				break;
			}
			var ret = new UdpDiscoveryEndpoint (ver, MulticastAddress);
			ret.MaxResponseDelay = MaxResponseDelay;
			TransportSettings.ApplyConfiguration (ret.TransportSettings);
			return ret;
		}