[英]Events not being thrown by ONVIF camera
我有几个要从中接收事件(例如,运动警报)的符合ONVIF的摄像机和编码器。
到目前为止,我设法订阅了(我认为)事件wsdl,但从未抛出任何事件。 我检查了设备中的设置,以确保它使用了运动检测,并且当运动存在时,我可以听到继电器的翻转,因此设置正确。
我将此问题作为尝试的参考,但由于未获得可接受的遮阳篷,因此我将再次询问。
这是我设置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());
}
相关问题的一个可能的解决方法是,当应该将其设置为WSAddressing10时,AddressingVersion设置为None,但是我早些时候遇到过,所以这不是解决此问题的方法。
我认为您感觉到的继电器翻转是关于IR模式而不是运动检测。尝试在ODM中打开相机。 它是ONVIF发现和事件订阅的开源实现。
不确定是否相关,但仅通过查看此代码,不应调用
_notificationConsumerServiceHost = new ServiceHost(_notificationConsumerService, new Uri("http://localhost:8085/NotificationConsumerService"));
是这样的:
_notificationConsumerServiceHost = new ServiceHost(_notificationConsumerService, new Uri("http://<RemoteIP>:8085/NotificationConsumerService"));
即,“本地主机”可能无法解析摄像机上的主机,在这种情况下,呼叫请求将丢失。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.