0

im trying to get live stream from onvif devices my program searchs and finds cameras IP and onvif Port successfully,but in the next step to get device information i face this error :

there was no endpoint listening at http://192.168.1.89/onvif/device_service that could accept the message.this often cause by an incorrect address or SOAP action.

i dont know what is wrong with my code even i want to get the time and date from the devices there is the same error! my code is :

  private Device deviceChannel = null;
    private System.ServiceModel.Channels.Binding binding = null;


    private string serverNetworkAddress;
    private string serviceAddress;
    private string serverUsername = "";
    private string serverPassword = "";

     InitializeComponent();

        serverUsername = OnvifUserTextBox.Text;
        serverPassword = OnvifPwdTextBox.Text;
        serverNetworkAddress = serverAddrTextBox.Text;
        serviceAddress = string.Format("http://{0}/onvif/device_service", serverNetworkAddress);

        //Create Binding
        binding = CreateBinding();
     private static System.ServiceModel.Channels.Binding CreateBinding()
    {


        HttpTransportBindingElement httpTransport = new HttpTransportBindingElement();

        TransportSecurityBindingElement transportSecurity = new TransportSecurityBindingElement();
        transportSecurity.EndpointSupportingTokenParameters.SignedEncrypted.Add(
            new UsernameTokenParameters());

        transportSecurity.AllowInsecureTransport = true;
        transportSecurity.IncludeTimestamp = false;

        TextMessageEncodingBindingElement me =
            new TextMessageEncodingBindingElement(MessageVersion.Soap12, Encoding.UTF8);

        return new CustomBinding(transportSecurity, me, httpTransport);
    }
   private static TChannel GetChannel<TChannel>       (System.ServiceModel.Channels.Binding binding,
        string serviceAddressText,
        string serverUsername,
        string serverPassword)
    {
        EndpointAddress serviceAddress = new EndpointAddress(serviceAddressText);
        ChannelFactory<TChannel> channelFactory =
            new ChannelFactory<TChannel>(binding, serviceAddress);

        // configure the username credentials on the channel factory 
        UsernameClientCredentials credentials =
            new UsernameClientCredentials(new UsernameInfo(serverUsername, serverPassword));

        // replace ClientCredentials with UsernameClientCredentials
        channelFactory.Endpoint.Behaviors.Remove(typeof(ClientCredentials));
        channelFactory.Endpoint.Behaviors.Add(credentials);

        return channelFactory.CreateChannel();
    }
 private void button2_Click(object sender, EventArgs e)
    {
      //getting the device information
        listBox.Items.Clear();
        serverUsername = OnvifUserTextBox.Text;
        serverPassword = OnvifPwdTextBox.Text;
        serverNetworkAddress = serverAddrTextBox.Text;
        serviceAddress = string.Format("http://{0}/onvif/device_service", serverNetworkAddress);

        // string model, firmwareVersion, serialNumber, hardwareId;

        try
        {
            // Create a client with given client endpoint configuration
            deviceChannel =

            GetChannel<Device>(binding, serviceAddress, serverUsername, serverPassword);

            // deviceChannel.GetDeviceInformation= (  out model, out FirmwareVersion, out SerialNumber, out HardwareId);
            //get date and time
            var timemamo = deviceChannel.GetSystemDateAndTime();
            listBox.Items.Add(timemamo);



          var info = deviceChannel.GetDeviceInformation(new GetDeviceInformationRequest());
          //MessageBox.Show(string.Format("Model: {0}", info.Model));

            string strManuf = string.Format("Manufacturer: {0}", info.Manufacturer);
            listBox.Items.Add(strManuf);

            string strModel = string.Format("Model: {0}", info.Model);
            listBox.Items.Add(strModel);
            string strFw = string.Format("Firmware Version: {0}", info.FirmwareVersion);
            listBox.Items.Add(strFw);

            string strSerialNo = string.Format("Serial Number: {0}", info.SerialNumber);
            listBox.Items.Add(strSerialNo);

            string strHwId = string.Format("Hardware Id: {0}", info.HardwareId);
            listBox.Items.Add(strHwId);



        }
        catch (Exception exception)
        {
            string str = string.Format("GetDeviceInformation():mamo " + exception.Message);
            listBox.Items.Add(str);

        }
    }
Mamo Ghandi
  • 77
  • 2
  • 10

3 Answers3

0

Your Onvif device might not listening on the default Port(s). Try to add the correct Port number (the Onvif Port, not the HTTP or RTSP) to the URL, for example: http://192.168.1.89:8182/onvif/device_service

aniski
  • 1,263
  • 1
  • 16
  • 31
  • yup thats it i create another app using WPF and it works! but in this project when i add port to uri another error uccured – Mamo Ghandi Sep 17 '16 at 08:07
0

Use 554 port which is a default port for live streaming in onvif

TheLostMind
  • 35,966
  • 12
  • 68
  • 104
0

Try to scan all open ports on your IP camera.

For example, in UNIX systems you may use command nmap -p- 192.168.1.89.

Then, try to open the same path for all found ports. In my camera port was far from standard: 8999, which did not appear in the fast scan mode without -p- flag.

Valia
  • 81
  • 1
  • 2