Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to discover onvif devices in C#

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?

like image 464
user1828855 Avatar asked Nov 16 '12 12:11

user1828855


People also ask

How do I find my ONVIF devices?

ONVIF Devices are discovered according WS-Discovery specification. You send a Probe message, and devices that match the Probe's constraints send back a ProbeMatch message, as described on page 13 and 14 in ONVIF Application Programmers Guide.

How do I know if my camera is ONVIF?

The easiest and the most reliable would be to just ask the camera's manufacturer or seller. Contact their customer care service, let them know the camera's model and firmware version, and ask if the ONVIF is supported in your camera.

How do I add a camera to ONVIF Device Manager?

Launch Onvif Device Manager, the device list will automatically show the devices that are compatible with Onvif. If you haven't found your devices, please click "Add" at the left end corner and input your IP address to add your cameras. Step 3. Input the name and password of your device to log in.


1 Answers

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.

    }
}
like image 120
Simon Wood Avatar answered Oct 04 '22 01:10

Simon Wood