c# - 如何在 C# 中发现 onvif 设备

标签 c# wcf ip-camera onvif ws-discovery

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

 <?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 设备?

最佳答案

只需使用 WCF web service discovery 功能。 ONVIF 遵循与 WCF 实现的相同标准。您需要使用 DiscoveryClient 类来发送探测。

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

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# - 如何在 C# 中发现 onvif 设备,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13416193/

相关文章:

c# - 如何在整个应用程序中添加彩色胶片

c# - 经过身份验证的 WCF : Getting the Current Security Context

c# - 使用客户端 Web 服务时出现内容错误

ip-camera - 通过 ONVIF 检索摄像机记录

c++ - 从网络摄像机获取图像

c# - 从 C# 8 中的 System.Reflection.Metadata 获取接口(interface)可为 null 的上下文元数据

c# - 处理 CAD 绘图中的不精确性

c# - 等价于其他语言的 C# "Block values"

c# - 如何在不读取结束的情况下中止来自 WCF 服务的流?

java - 无法在 IP 摄像机上对动态生成的图像进行快速 I/O