2016-09-05 40 views
0

IM試圖從ONVIF設備的現場直播我的程序searchs,發現攝像頭的IP和ONVIF端口成功,但在接下來的步驟中獲得設備信息我面對這樣的錯誤:從ONVIF設備獲得實時視頻流

沒有端點監聽http://192.168.1.89/onvif/device_service可以接受該消息。這通常是由不正確的地址或SOAP操作引起的。

我不知道我的代碼有什麼問題,即使我想從設備中獲取時間和日期也是一樣的錯誤! 我的代碼是:

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); 

     } 
    } 

回答

0

您的ONVIF設備可能不監聽默認端口(S)。儘量正確的端口號(ONVIF端口,而不是HTTP或RTSP)添加到URL,例如: http://192.168.1.89:8182/onvif/device_service

+0

燁完蛋了我使用WPF創建另一個應用程序,它的工作原理!但在這個項目中,當我添加端口到uri另一個錯誤uccured –

0

使用554端口這是ONVIF實時流默認端口