【问题标题】:Events not being thrown by ONVIF cameraONVIF 摄像头未抛出事件
【发布时间】:2015-04-21 08:19:41
【问题描述】:

我有几个符合 ONVIF 标准的摄像机和编码器,我想从中接收事件,例如运动警报。

到目前为止,我设法(我认为)订阅了事件 wsdl,但没有抛出任何事件。我检查了设备中的设置以确保它使用运动检测,并且当存在运动时我可以听到继电器翻转,因此设置正确。

我使用this question 作为我尝试的参考,但由于它没有得到接受的遮阳篷,我会再问一次。

以下是我设置 wsdl 文件的方法:

ServicePointManager.Expect100Continue = false;
EndpointAddress endPointAddress = new EndpointAddress("http://" + CameraInformation.IpAddress + "/onvif/device_service");
HttpTransportBindingElement httpTransportBinding = new HttpTransportBindingElement { AuthenticationScheme = AuthenticationSchemes.Digest };
httpTransportBinding.KeepAliveEnabled = true;
TextMessageEncodingBindingElement textMessageEncodingBinding = new TextMessageEncodingBindingElement { MessageVersion = MessageVersion.CreateVersion(EnvelopeVersion.Soap12, AddressingVersion.WSAddressing10) };
PasswordDigestBehavior passwordDigestBehavior = new PasswordDigestBehavior(CameraInformation.Username, CameraInformation.Password);

CustomBinding customBinding = new CustomBinding(textMessageEncodingBinding, httpTransportBinding);
customBinding.SendTimeout = new TimeSpan(0, 0, 10);

这是我初始化消费者服务的方式:

_notificationConsumerService = new NotificationConsumerService();
_notificationConsumerService.NewNotification += _notificationConsumerService_NewNotification;
_notificationConsumerServiceHost = new ServiceHost(_notificationConsumerService, new Uri("http://localhost:8085/NotificationConsumerService"));
_notificationConsumerServiceHost.Open();

NotificationConsumerService 类:

[ServiceBehavior(InstanceContextMode = InstanceContextMode.Single, ConcurrencyMode = ConcurrencyMode.Single, AddressFilterMode = AddressFilterMode.Any)]
public class NotificationConsumerService : OnvifEvents.NotificationConsumer
{
      public event EventHandler<EventArgs<OnvifEvents.Notify1>> NewNotification;

      public void Notify(OnvifEvents.Notify1 request)
      {
          var threadSafeEventHandler = NewNotification;
          if (threadSafeEventHandler != null)
              threadSafeEventHandler.Invoke(this, new EventArgs<OnvifEvents.Notify1>(request));
      }

      public Task NotifyAsync(System21.OnvifEvents.Notify1 request)
      {
         return new Task(() =>
            {
                 //return something?
            });
     }
}

     public class EventArgs<T> : EventArgs
     {
        public EventArgs(T data)
        {
            Data = data;
        }
        public T Data { get; set; }
     }

加载通知生产者客户端:

    var serviceAddress = new EndpointAddress(Capabilities.Events.XAddr.ToString());
    if (!string.IsNullOrWhiteSpace(CameraInformation.Username))
    {
         NotificationProducerClient.ClientCredentials.UserName.UserName = CameraInformation.Username;
         NotificationProducerClient.ClientCredentials.UserName.Password = CameraInformation.Password;
    }

最后添加事件订阅:

if (Capabilities.Events == null)
      throw new ApplicationException("The streamer info does not support event");
try
{
       if (NotificationProducerClient == null)
            LoadNotificationProducerClient();

       var subScribe = new OnvifEvents.Subscribe()
       {
            ConsumerReference = new OnvifEvents.EndpointReferenceType
            {
                  Address = new OnvifEvents.AttributedURIType { Value = _notificationConsumerServiceHost.BaseAddresses.First().ToString() },
            }
       };
       if (!string.IsNullOrWhiteSpace(initialTerminationTime))
            subScribe.InitialTerminationTime = initialTerminationTime;

       OnvifEvents.SubscribeResponse response = NotificationProducerClient.Subscribe(subScribe);
}

Catch (FaultException ex)
{
    Console.Write(ex.ToString());
}
catch (Exception ex)
{
    Console.Write(ex.ToString());
}

来自相关问题的一个可能的 awnser 是 AddressingVersion 在应该设置为 WSAddressing10 时设置为 None 但我之前遇到过这个问题,所以它不是解决这个问题的方法。

【问题讨论】:

    标签: c# events onvif


    【解决方案1】:

    我认为你觉得继电器翻转是关于 IR 模式而不是运动检测。尝试在ODM 中打开你的相机。它是 ONVIF 发现和事件订阅的开源实现。

    【讨论】:

    • 继电器翻转确实是由运动检测触发的(该设备具有可用于运动检测的输出引脚)。我使用 ODM 来查看设备是否真的抛出了事件,并且确实如此。
    【解决方案2】:

    不确定这是否相关,但仅通过查看此代码,不应该调用

    _notificationConsumerServiceHost = new ServiceHost(_notificationConsumerService, new Uri("http://localhost:8085/NotificationConsumerService"));
    

    是这样的:

    _notificationConsumerServiceHost = new ServiceHost(_notificationConsumerService, new Uri("http://<RemoteIP>:8085/NotificationConsumerService"));
    

    即“localhost”可能无法解析摄像机上的主机,在这种情况下呼叫请求会丢失。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-05-18
      • 2022-09-26
      • 1970-01-01
      • 2015-04-13
      • 1970-01-01
      • 2023-04-10
      • 2015-06-28
      相关资源
      最近更新 更多