2013-05-16 84 views
2

我有3個ONVIF相機(博世,Pansonic和AXIS)。我找到了使用WS-Discovery的相機,並可以使用GetDeviceInformation從相機獲取信息。我的問題是,當我試圖從中獲取信息時,AXIS相機返回(400)錯誤請求,另外兩個像魅力一樣工作。如何用ONVIF驗證AXIS相機

我已經從SourceForge安裝了ONVIF設備管理器。如果我在節目中輸入登錄憑證,我可以通過AXIS相機傳送實時視頻。如果我沒有輸入任何登錄憑證,我可以找到相機,但不能傳送任何視頻。所以基於此,我得出結論,相機配置正確。

我認爲它與綁定上的登錄憑證有關,但無法弄清楚什麼是錯誤的。

我的代碼看起來像這樣

private void CustomBinding2() 
{ 
     try 
     { 
      const string SERVICE_ADDRESS_DIRECT = "http://192.168.1.72/onvif/device_service"; //400 bad request 
      const string USERNAME = "cbk"; 
      const string PASSWORD = "12"; 

      HttpTransportBindingElement httpTransportBindingElement = new HttpTransportBindingElement(); 
      httpTransportBindingElement.MaxReceivedMessageSize = Int32.MaxValue; 
      httpTransportBindingElement.KeepAliveEnabled = false; 
      httpTransportBindingElement.MaxBufferSize = Int32.MaxValue; 
      httpTransportBindingElement.ProxyAddress = null; 
      httpTransportBindingElement.BypassProxyOnLocal = true; 
      httpTransportBindingElement.UseDefaultWebProxy = false; 
      httpTransportBindingElement.TransferMode = TransferMode.StreamedResponse; 
      httpTransportBindingElement.AuthenticationScheme = AuthenticationSchemes.Basic; 

      TextMessageEncodingBindingElement messegeElement = new TextMessageEncodingBindingElement(); 
      messegeElement.MessageVersion = MessageVersion.CreateVersion(EnvelopeVersion.Soap12, AddressingVersion.None); 

      CustomBinding binding = new CustomBinding(messegeElement, httpTransportBindingElement); 
      binding.CloseTimeout = TimeSpan.FromSeconds(30.0); 
      binding.OpenTimeout = TimeSpan.FromSeconds(30.0); 
      binding.SendTimeout = TimeSpan.FromMinutes(10.0); 
      binding.ReceiveTimeout = TimeSpan.FromMinutes(3.0); 

      EndpointAddress serviceAddress = new EndpointAddress(SERVICE_ADDRESS_DIRECT); 

      ChannelFactory<Device> channelFactory = new ChannelFactory<Device>(binding, serviceAddress); 
      channelFactory.Credentials.UserName.UserName = USERNAME; 
      channelFactory.Credentials.UserName.Password = PASSWORD; 

      Device channel = channelFactory.CreateChannel(); 

      string model, firmwareVersion, serialNumber, hardwareId; 
      channel.GetDeviceInformation(out model, out firmwareVersion, out serialNumber, out hardwareId); 
      MessageBox.Show(string.Format("Model: {0}", model)); 
     } 
     catch (Exception e) 
     { 
      MessageBox.Show(e.Message); 
     } 
} 

回答

4

問題解決了......

一個是騙我的大部分東西,是,AXIS攝像機和客戶端(PC)必須是時間同步在+ -5秒內。如果我改變個人電腦的時間,我只會收到400個不好的要求。如果時間匹配一切正常!

  DateTime UTCTime = DateTime.UtcNow; 

      tbInfo.AppendText(string.Format("Client Local Time: {0}\n", DateTime.Now.ToString("HH:mm:ss"))); 
      tbInfo.AppendText(string.Format("Client UTC Time: {0}\n", UTCTime.ToString("HH:mm:ss"))); 
      tbInfo.AppendText("\n\n"); 

      HttpTransportBindingElement httpTransport = new HttpTransportBindingElement(); 

      TransportSecurityBindingElement transportSecurity = new TransportSecurityBindingElement(); 
      transportSecurity.EndpointSupportingTokenParameters.SignedEncrypted.Add(new UsernameTokenParameters()); 
      transportSecurity.AllowInsecureTransport = true; 
      transportSecurity.IncludeTimestamp = false; 

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

      CustomBinding binding = new CustomBinding(transportSecurity, textMessageEncoding, httpTransport); 

      EndpointAddress serviceAddress = new EndpointAddress(addressDirect); 
      ChannelFactory<Device> channelFactory = new ChannelFactory<Device>(binding, serviceAddress); 

      UsernameClientCredentials credentials = new UsernameClientCredentials(new UsernameInfo(username, password)); 

      channelFactory.Endpoint.Behaviors.Remove(typeof(ClientCredentials)); 
      channelFactory.Endpoint.Behaviors.Add(credentials); 

      Device channel = channelFactory.CreateChannel(); 

      var unitTime = channel.GetSystemDateAndTime(new GetSystemDateAndTimeRequest()); 
      tbInfo.AppendText(string.Format("Camera Local Time: {0}:{1}:{2}\n", unitTime.SystemDateAndTime.LocalDateTime.Time.Hour, unitTime.SystemDateAndTime.LocalDateTime.Time.Minute, unitTime.SystemDateAndTime.LocalDateTime.Time.Second)); 
      tbInfo.AppendText(string.Format("Camera UTC Time: {0}:{1}:{2}\n", unitTime.SystemDateAndTime.UTCDateTime.Time.Hour, unitTime.SystemDateAndTime.UTCDateTime.Time.Minute, unitTime.SystemDateAndTime.UTCDateTime.Time.Second)); 

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