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?

user1828855
  • 123
  • 1
  • 1
  • 6

1 Answers1

19

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.

    }
}
J Pollack
  • 2,788
  • 3
  • 29
  • 43
Simon Wood
  • 624
  • 5
  • 9
  • Dear Simon, I've tried this but did not get any response. I'm confuse about this SOAP element dn:NetworkVideoTransmitter How can is add this in FindCriteria? – user1828855 Nov 17 '12 at 08:25
  • 3
    Add it to the contract type names of the find criteria. FindCriteria.ContractTypeNames. Depending on the version of onvif NetworkVideoTransmitter may be specified as a scope not a Type. Try doing an async find without criteria. Using a call back this will allow you to inspect responses from all discoverable devices your onvif device should be included. From this information you should be able to perform a more targeted find. – Simon Wood Nov 17 '12 at 13:42
  • 1
    Hurah....! I got responses from my ONVIF Device. Thnx alot for this Guidance Simon. – user1828855 Nov 23 '12 at 07:44
  • NOTE: According to the WS-Discovery specification, your ONVIF devices should answer even if there is no "ContractTypeNames" criteria. The purpose of the criteria is to reduce the number of responses, not to enable responses. Many devices, however, are too restrictive in their interpretation of the specification. Some apps will send out Probes with different criteria, in the hopes of finding all the devices they actually care about, ignoring responses from devices they don't truly care about. – Jesse Chisholm Sep 26 '14 at 15:48