如何在C#中发现onvif设备

use*_*855 10 c# wcf ws-discovery ip-camera onvif

我正在开发一个应用程序,它将探测连接在网络上的ONVIF设备以进行自动发现.根据ONVIF Core规范,Probe消息的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>
Run Code Online (Sandbox Code Playgroud)

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

Sim*_*ood 16

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设备是否已响应.如果您仍然无法获得响应,则可能是网络或设备问题.如果您确实收到了回复,则可以优化查找条件以仅通知所需类型.

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.

    }
}
Run Code Online (Sandbox Code Playgroud)

  • 将其添加到查找条件的合同类型名称.FindCriteria.ContractTypeNames.根据onvif的版本,NetworkVideoTransmitter可以指定为范围而不是Type.尝试在没有条件的情况下进行异步查找.使用回调功能,您可以检查所有可发现设备的响应,包括您的onvif设备.根据这些信息,您应该能够执行更有针对性的查找. (2认同)