Пример #1
0
 public static Service[] GetServices(BaseOnvifTest test, DeviceClient client, bool includeCapabilities)
 {
     Service[] services = null;
     RunStep(test, () => { services = client.GetServices(includeCapabilities); }, "Get Services");
     DoRequestDelay(test);
     return(services);
 }
        private void ConnectCam()
        {
            bool inError = false;

            deviceUri = new UriBuilder("http:/onvif/device_service");

            string[] addr = address.Text.Split(':');
            deviceUri.Host = addr[0];
            if (addr.Length == 2)
            {
                deviceUri.Port = Convert.ToInt16(addr[1]);
            }

            System.ServiceModel.Channels.Binding binding;
            HttpTransportBindingElement          httpTransport = new HttpTransportBindingElement();

            httpTransport.AuthenticationScheme = System.Net.AuthenticationSchemes.Digest;
            binding = new CustomBinding(new TextMessageEncodingBindingElement(MessageVersion.Soap12WSAddressing10, Encoding.UTF8), httpTransport);

            try
            {
                DeviceClient device   = new DeviceClient(binding, new EndpointAddress(deviceUri.ToString()));
                Service[]    services = device.GetServices(false);
                Service      xmedia2  = services.FirstOrDefault(s => s.Namespace == "http://www.onvif.org/ver20/media/wsdl");

                if (xmedia2 != null)
                {
                    media = new Media2Client(binding, new EndpointAddress(deviceUri.ToString()));
                    media.ClientCredentials.HttpDigest.ClientCredential.UserName = user.Text;
                    media.ClientCredentials.HttpDigest.ClientCredential.Password = password.Password;
                    media.ClientCredentials.HttpDigest.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation;
                    profiles = media.GetProfiles(null, null);

                    // Make sure that the list is empty before adding new items
                    listBox.Items.Clear();
                    if (profiles != null)
                    {
                        foreach (MediaProfile p in profiles)
                        {
                            listBox.Items.Add(p.Name);
                        }
                    }

                    // Enable Manage Profile btn
                    create_profile_btn.IsEnabled = true;
                }
                listBox.SelectionChanged += OnSelectionChanged;
                video.MediaPlayer.VlcLibDirectoryNeeded += OnVlcControlNeedsLibDirectory;
                video.MediaPlayer.Log += MediaPlayer_Log;
                video.MediaPlayer.EndInit();
            }
            catch (Exception ex)
            {
                textBox.Text = ex.Message;
                inError      = true;
            }
            changeErrorLogColor(inError);
        }
Пример #3
0
        public static string GetServiceAddress(this DeviceClient device, string serviceNs)
        {
            string address = string.Empty;

            Service[] services = device.GetServices(false);
            Service   service  = services.FindService(serviceNs);

            if (service != null)
            {
                address = service.XAddr;
            }
            return(address);
        }
Пример #4
0
        private void SetupSystem()
        {
            try
            {
                System.ServiceModel.Channels.CustomBinding binding;
                Device_Client = CustomBindingsAndClients.GetClient(IPAddress, 80, 0, out binding, out deviceUri, userName, password);
                Device.Service[] service = Device_Client.GetServices(false);
                //Check if they contain media and that we have made contact TODO wrap in a try catch block
                Device.Service checkk_media = service.FirstOrDefault(s => s.Namespace == "");
                if (checkk_media != null)
                {
                    media_client = new Media2Client(binding, new EndpointAddress(deviceUri.ToString()));
                    media_client.ClientCredentials.HttpDigest.ClientCredential.UserName = userName;
                    media_client.ClientCredentials.HttpDigest.ClientCredential.Password = password;
                    media_client.ClientCredentials.HttpDigest.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation;

                    //Get camera Profiles.
                    try
                    {
                        profiles = media_client.GetProfiles(null, null);
                    }
                    catch
                    {
                        //Do something
                    }
                    if (profiles != null)
                    {
                        foreach (var p in profiles)
                        {
                            listBox_Profiles.Add(p.Name);
                            //Confirmed: Profiles listed in box are a match to profiles setup on camera.
                        }
                    }
                }
            }
            catch
            {
                string            message = "You did not enter a valid IP address, username, or password?";
                string            caption = "Error Detected in Input";
                MessageBoxButtons buttons = MessageBoxButtons.OK;
                DialogResult      result;

                // Displays the MessageBox.
                result = MessageBox.Show(message, caption, buttons);
            }
        }
        public static string Test(Structures set)
        {
            var messageElement = new TextMessageEncodingBindingElement();

            messageElement.MessageVersion = MessageVersion.CreateVersion(EnvelopeVersion.Soap12, AddressingVersion.None);
            HttpTransportBindingElement httpBinding = new HttpTransportBindingElement();

            httpBinding.AuthenticationScheme = AuthenticationSchemes.Basic;
            CustomBinding   bind         = new CustomBinding(messageElement, httpBinding);
            EndpointAddress mediaAddress = new EndpointAddress(set.GetONVIF + "/onvif/Device");
            DeviceClient    client       = new DeviceClient(bind, mediaAddress);

            client.ClientCredentials.UserName.UserName = set.Login;
            client.ClientCredentials.UserName.Password = set.Password;

            var t = client.GetServices(true);

            return("");
        }
Пример #6
0
        /// <summary>
        /// Retrieves Onvif service URIs from the device and stores them in the ServiceUris dictionary
        /// </summary>
        /// <param name="ip">IP Address</param>
        /// <param name="onvifPort">Port to connect on (normally HTTP - 80)</param>
        /// <param name="user">User name</param>
        /// <param name="password">User's Password</param>
        private void GetOnvifUris(Camera cam, int onvifPort)
        {
            ServiceUris.Clear();

            DeviceClient client = OnvifServices.GetOnvifDeviceClient(cam.IP, onvifPort, DeviceTimeOffset, cam.User, cam.Password);

            Service[] svc = client.GetServices(IncludeCapability: false); // Bosch Autodome 800 response can't be deserialized if IncludeCapability enabled
            foreach (Service s in svc)
            {
                ServiceUris.Add(s.Namespace, s.XAddr);
            }

            // Check if this is an Onvif enabled PTZ
            if (ServiceUris.ContainsKey(OnvifNamespace.PTZ))
            {
                IsPtz = true;
            }
            else
            {
                IsPtz = false;
            }
        }
Пример #7
0
        public IReadOnlyList <IService> GetServices()
        {
            var loadedServices = Camera.AvailableServices;

            if (loadedServices.Count > 0)
            {
                return(loadedServices);
            }

            var services = deviceClient.GetServices(false);

            List <IService> availableServices = new List <IService>(services.Length);

            foreach (var rawService in services)
            {
                var service = ServiceFactory.CreateService(rawService.Namespace, this.Camera, rawService.XAddr);
                if (service != null)
                {
                    availableServices.Add(service);
                }
            }

            return(availableServices.AsReadOnly());
        }
Пример #8
0
        private void GetServices(DeviceClient client)
        {
            // GetCapabilities is now deprecated (as of v2.1) - replaced by GetServices (Older devices may still use)
            OnvifDeviceManagementServiceReference.Capabilities capabilities = client.GetCapabilities(new CapabilityCategory[] { CapabilityCategory.All });

            if (capabilities.Analytics != null)
            {
                lbxCapabilities.Items.Add("Analytics");
            }
            if (capabilities.Events != null)
            {
                lbxCapabilities.Items.Add("Events");
            }
            if (capabilities.Extension != null)
            {
                lbxCapabilities.Items.Add("Extension");
            }
            if (capabilities.Imaging != null)
            {
                lbxCapabilities.Items.Add("Imaging");
            }
            if (capabilities.Media != null)
            {
                lbxCapabilities.Items.Add("Media");
            }
            if (capabilities.PTZ != null)
            {
                lbxCapabilities.Items.Add("PTZ");
            }

            lbxCapabilities.Items.Add("");
            ServiceUris.Clear();

            Service[] svc = null;
            try
            {
                svc = client.GetServices(IncludeCapability: true);
            }
            catch
            {
                // Bosch Autodome 800 response can't be deserialized if IncludeCapability enabled
                // Ignore and try with IncludeCapability disabled
            }

            // Try with IncludeCapability disabled
            if (svc == null)
            {
                svc = client.GetServices(IncludeCapability: false); // Bosch Autodome 800 response can't be deserialized if IncludeCapability enabled
            }

            foreach (Service s in svc)
            {
                Console.WriteLine(s.XAddr + " " + " " + s.Namespace);  // Not present on Axis + s.Capabilities.NamespaceURI);
                lbxCapabilities.Items.Add(string.Format("{0}", s.Namespace));
                ServiceUris.Add(s.Namespace, s.XAddr);

                if (s.Capabilities != null)
                {
                    foreach (System.Xml.XmlNode x in s.Capabilities)
                    {
                        Console.WriteLine(string.Format("\t{0}", x.LocalName));
                        lbxCapabilities.Items.Add(string.Format("    {0}", x.LocalName));
                        if (x.Attributes.Count > 0)
                        {
                            foreach (System.Xml.XmlNode a in x.Attributes)
                            {
                                Console.WriteLine(string.Format("\t\t{0} = {1}", a.Name, a.Value));
                                lbxCapabilities.Items.Add(string.Format("        {0} = {1}", a.Name, a.Value));
                            }
                        }
                    }
                }
            }

            //DeviceServiceCapabilities dsc = client.GetServiceCapabilities();
        }
Пример #9
0
        void InitializeProxies(SimulatorStartParameters parameters)
        {
            _proxies = new List <ServiceProxy>();

            string             deviceAddress = parameters.IPAddress + "onvif/device_service/";
            DeviceServiceProxy deviceProxy   = new DeviceServiceProxy(deviceAddress,
                                                                      parameters.DeviceAddress);

            deviceProxy.DataTransmitted += new NetworkEvent(Proxy_DataTransmitted);
            _proxies.Add(deviceProxy);

            //
            // initialize other proxies
            //

            CustomBinding custombindingSoap12 = new CustomBinding();

            custombindingSoap12.Elements.Add(new TextMessageEncodingBindingElement(MessageVersion.Soap12, Encoding.UTF8));
            custombindingSoap12.Elements.Add(new HttpTransportBindingElement());

            Dictionary <string, string> replacements = new Dictionary <string, string>();

            replacements.Add(OnvifService.DEVICE, deviceAddress);

            DeviceClient deviceClient = new DeviceClient(custombindingSoap12, new EndpointAddress(parameters.DeviceAddress));

            Service[] services;
            try
            {
                services = deviceClient.GetServices(false);
            }
            catch (FaultException exc)
            {
                deviceClient.Close();
                deviceClient = new DeviceClient(custombindingSoap12, new EndpointAddress(parameters.DeviceAddress));
                deviceClient.Endpoint.Behaviors.Add(new Transport.SecurityBehavior()
                {
                    UserName = parameters.Username, Password = parameters.Password
                });
                services = deviceClient.GetServices(false);
            }
            deviceClient.Close();

            foreach (Service service in services)
            {
                string localAddress = string.Empty;
                switch (service.Namespace)
                {
                case OnvifService.ACCESSCONTROL:
                    localAddress = "onvif/access_control/";
                    break;

                case OnvifService.DOORCONTROL:
                    localAddress = "onvif/door_control/";
                    break;
                }

                if (!string.IsNullOrEmpty(localAddress))
                {
                    string       address = parameters.IPAddress + localAddress;
                    ServiceProxy proxy   = new ServiceProxy(address, service.XAddr);
                    proxy.DataTransmitted += new NetworkEvent(Proxy_DataTransmitted);
                    _proxies.Add(proxy);
                    replacements.Add(service.Namespace, address);
                }
            }

            deviceProxy.SetReplacements(replacements);
        }