Beispiel #1
0
        static void Main(string [] args)
        {
            try {
                /* Discovery doesn't work in Mono
                 * var endPoint = new UdpDiscoveryEndpoint (DiscoveryVersion.WSDiscoveryApril2005);
                 *
                 * var discoveryClient = new DiscoveryClient (endPoint);
                 *
                 * discoveryClient.FindProgressChanged += discoveryClient_FindProgressChanged;
                 * discoveryClient.FindCompleted += (sender, e) => {
                 *      Console.WriteLine ("Discovery finished");
                 * };
                 * FindCriteria findCriteria = new FindCriteria ();
                 * //findCriteria.Duration = TimeSpan.MaxValue;
                 * findCriteria.Duration = TimeSpan.FromSeconds (10);
                 * findCriteria.MaxResults = int.MaxValue;
                 * discoveryClient.FindAsync (findCriteria);
                 *
                 * //Console.ReadKey ();
                 */

                HttpTransportBindingElement httpBinding = new HttpTransportBindingElement();
                httpBinding.AuthenticationScheme = AuthenticationSchemes.Digest;
                var messageElement = new TextMessageEncodingBindingElement();
                // FIXME: Probe for Soap12 if Soap11 fails
                messageElement.MessageVersion = MessageVersion.CreateVersion(EnvelopeVersion.Soap12, AddressingVersion.None);
                CustomBinding   binding = new CustomBinding(messageElement, httpBinding);
                EndpointAddress address = new EndpointAddress(@"http://192.168.1.130:8080/onvif/device_service");

                OnvifServices.OnvifDeviceService.DeviceClient device = new OnvifServices.OnvifDeviceService.DeviceClient(binding, address);
                device.ClientCredentials.UserName.UserName = @"admin";
                device.ClientCredentials.UserName.Password = @"admin";

                var dateTime = device.GetSystemDateAndTime();
                var services = device.GetServices(true);
                foreach (var service in services)
                {
                    if (service.Namespace == "http://www.onvif.org/ver10/media/wsdl")
                    {
                        OnvifServices.OnvifMediaService.MediaClient client = new OnvifServices.OnvifMediaService.MediaClient(binding, address);
                        client.ClientCredentials.UserName.UserName = @"admin";
                        client.ClientCredentials.UserName.Password = @"admin";
                        var profiles = client.GetProfiles();

                        // use the first profile (the device has at least one media profile).
                        var targetProfileToken = profiles [0].token;
                        // set the GetStreamUriRequest paramater
                        var streamSetup = new OnvifServices.OnvifMediaService.StreamSetup();
                        streamSetup.Stream             = OnvifServices.OnvifMediaService.StreamType.RTPUnicast;
                        streamSetup.Transport          = new OnvifServices.OnvifMediaService.Transport();
                        streamSetup.Transport.Protocol = OnvifServices.OnvifMediaService.TransportProtocol.RTSP;
                        streamSetup.Transport.Tunnel   = null;
                        var mediaUri = client.GetStreamUri(streamSetup, targetProfileToken);
                    }
                }
            } catch (Exception ex) {
                Console.Out.WriteLine($"Error: {ex.Message} \r\n{ex.StackTrace}");
            }
        }
Beispiel #2
0
        static void AddEndPoint(EndpointDiscoveryMetadata endpoint)
        {
            if (endpoint.ListenUris != null && endpoint.ListenUris.Count > 0)
            {
                foreach (var uri in endpoint.ListenUris)
                {
                    string uriString = uri.AbsoluteUri;


                    HttpTransportBindingElement httpBinding = new HttpTransportBindingElement();
                    httpBinding.AuthenticationScheme = AuthenticationSchemes.Digest;
                    var messageElement = new TextMessageEncodingBindingElement();
                    // FIXME: Probe for Soap12 if Soap11 fails
                    messageElement.MessageVersion = MessageVersion.CreateVersion(EnvelopeVersion.Soap12, AddressingVersion.None);
                    CustomBinding   binding = new CustomBinding(messageElement, httpBinding);
                    EndpointAddress address = new EndpointAddress(uriString);

                    OnvifServices.OnvifDeviceService.DeviceClient device = new OnvifServices.OnvifDeviceService.DeviceClient(binding, address);
                    //device.ClientCredentials.HttpDigest.ClientCredential = new NetworkCredential("admin", "admin");
                    //device.ClientCredentials.UserName.UserName = @"admin";
                    //device.ClientCredentials.UserName.Password = @"admin";
                    try {
                        //device.Open();

                        var dateTime = device.GetSystemDateAndTime();
                        //var hostName = device.GetHostname();

                        /*
                         * var caps = device.GetCapabilities(new OnvifServices.OnvifDeviceService.CapabilityCategory[] {
                         *       OnvifServices.OnvifDeviceService.CapabilityCategory.All
                         * });
                         */
                        //string model, firmware, serialNumber, hardwareId;
                        //string deviceName = device.GetDeviceInformation(out model, out firmware, out serialNumber, out hardwareId);

                        var services = device.GetServices(true);
                        foreach (var service in services)
                        {
                            if (service.Namespace == "http://www.onvif.org/ver10/media/wsdl")
                            {
                                OnvifServices.OnvifMediaService.MediaClient client = new OnvifServices.OnvifMediaService.MediaClient(binding, address);
                                var profiles = client.GetProfiles();
                            }
                        }


                        Console.WriteLine($"{uriString} --> OK");
                        device.Close();
                    } catch (Exception ex) {
                        Console.WriteLine($"{uriString} --> KO");
                    }
                }
            }
        }