如何在 C# 中发现 onvif 设备 [英] How to discover onvif devices in C#

查看:100
本文介绍了如何在 C# 中发现 onvif 设备的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个应用程序,它将探测连接到网络上的 ONVIF 设备以进行自动发现.根据 ONVIF 核心规范,探测消息的 SOAP 格式为:

I'm developing an application that will probe ONVIF devices attached on network for auto-discovery. According to ONVIF Core specification SOAP format of Probe message is :

 <?xml version="1.0" encoding="UTF-8"?>
<e:Envelope xmlns:e="http://www.w3.org/2003/05/soap-envelope"
xmlns:w="http://schemas.xmlsoap.org/ws/2004/08/addressing"
xmlns:d="http://schemas.xmlsoap.org/ws/2005/04/discovery"
xmlns:dn="http://www.onvif.org/ver10/network/wsdl">
<e:Header>
<w:MessageID>uuid:84ede3de-7dec-11d0-c360-f01234567890</w:MessageID>
<w:To e:mustUnderstand="true">urn:schemas-xmlsoap-org:ws:2005:04:discovery</w:To>
<w:Action
a:mustUnderstand="true">http://schemas.xmlsoap.org/ws/2005/04/discovery/Pr
obe</w:Action>
</e:Header>
<e:Body>
<d:Probe>
<d:Types>dn:NetworkVideoTransmitter</d:Types>
</d:Probe>
</e:Body>
</e:Envelope>

如何在 WCF 中发送此消息以发现 onvif 设备?

How can i send this message in WCF to discover onvif deivce?

推荐答案

只需使用 WCF Web 服务发现 功能.ONVIF 遵循与 WCF 实施的标准相同的标准.您需要使用 DiscoveryClient 类来发送探测.

Just use the WCF web service discovery features. ONVIF follows the same standard as that implemented by WCF. You'll need to use the DiscoveryClient class to send the probe.

我已经有一段时间没有这样做了,所以它可能不完全正确,但您的代码应该如下所示.多播探测将找到所有可发现的设备.您可以通过检查事件处理程序中每个响应的元数据来检测您的 onvif 设备是否已响应.如果您仍然无法获得响应,则可能是网络或设备问题.如果您确实收到了回复,您可以改进您的查找条件,以仅通知所需的类型.

It's been a while since I've done it so it might not be exactly right but your code should look something like the following. The multicast probe will find all discoverable devices. You can detect if your onvif device has responded by inspecting the metadata for each response in the event handler. If you're still unable to get a response its probably a network or device issue. If you do get a response you can refine your find criteria to only notify of required types.

class Program
{
    static void Main(string[] args)
    {
        var endPoint = new UdpDiscoveryEndpoint( DiscoveryVersion.WSDiscoveryApril2005 );

        var discoveryClient = new DiscoveryClient(endPoint);

        discoveryClient.FindProgressChanged += discoveryClient_FindProgressChanged;

        FindCriteria findCriteria = new FindCriteria();
        findCriteria.Duration = TimeSpan.MaxValue;
        findCriteria.MaxResults = int.MaxValue;
        // Edit: optionally specify contract type, ONVIF v1.0
        findCriteria.ContractTypeNames.Add(new XmlQualifiedName("NetworkVideoTransmitter",
            "http://www.onvif.org/ver10/network/wsdl"));

        discoveryClient.FindAsync(findCriteria);

        Console.ReadKey();
    }

    static void discoveryClient_FindProgressChanged(object sender, FindProgressChangedEventArgs e)
    {
        //Check endpoint metadata here for required types.

    }
}

这篇关于如何在 C# 中发现 onvif 设备的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆