How to discover onvif devices in C#

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-04 18:21:12

问题


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>

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


回答1:


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.

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.

    }
}


来源:https://stackoverflow.com/questions/13416193/how-to-discover-onvif-devices-in-c-sharp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!