C#Onvif发现请求-未收到从网络摄像机发送的响应

时间:2018-09-04 16:00:30

标签: c# udp discovery onvif

我们正在尝试获取基本的Onvif发现C#程序,以发现本地网络上的摄像机。我们可以使用现成的工具(例如Onvif Device Manager)来发现摄像机。使用Wireshark,我们可以看到Onvif DM发送的UDP请求以及来自摄像机的响应。

当我们运行基本的Onvif发现控制台应用程序时,Wireshark会向我们显示正在广播的几乎相同的UDP请求,并且在1秒钟内我们可以看到来自3个摄像机的网络响应。但是我们的应用程序看不到响应:永远不会调用我们的DiscoveryClient FindProgressChanged事件处理程序,并且由DiscoveryClient的Find方法返回的Endpoints集合为空。

这是我们的Discovery控制台应用程序:

using System;
using System.ServiceModel.Discovery;
using System.Xml;

namespace DiscoveryClient
{
    public class Program
    {
        public static void Main(string[] args)
        {
            var endPoint = new UdpDiscoveryEndpoint(DiscoveryVersion.WSDiscoveryApril2005);

            var discoveryClient = new System.ServiceModel.Discovery.DiscoveryClient(endPoint);

            discoveryClient.FindProgressChanged += DiscoveryClient_FindProgressChanged;

            var findCriteria = new FindCriteria
            {
                Duration = TimeSpan.FromSeconds(10),
                MaxResults = int.MaxValue
            };

            findCriteria.ContractTypeNames.Add(new XmlQualifiedName("NetworkVideoTransmitter", @"http://www.onvif.org/ver10/network/wsdl"));

            Console.WriteLine("Initiating find operation.");
            var response = discoveryClient.Find(findCriteria);
            Console.WriteLine($"Operation returned - Found {response.Endpoints.Count} endpoints.");

            Console.ReadKey();
        }

        private static void DiscoveryClient_FindProgressChanged(object sender, FindProgressChangedEventArgs e)
        {
            Console.WriteLine($"Found this: {e}");
        }
    }
}

这是由应用程序生成的示例UDP发现请求(这与Onvif DM生成的请求之间的唯一区别是探针中的Duration元素)

<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:a="http://schemas.xmlsoap.org/ws/2004/08/addressing">
<s:Header>
    <a:Action s:mustUnderstand="1">http://schemas.xmlsoap.org/ws/2005/04/discovery/Probe</a:Action>
    <a:MessageID>urn:uuid:3445e6a6-0751-4953-9071-394ab3f85fcb</a:MessageID>
    <a:ReplyTo><a:Address>http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous</a:Address></a:ReplyTo>
    <a:To s:mustUnderstand="1">urn:schemas-xmlsoap-org:ws:2005:04:discovery</a:To>
</s:Header>
<s:Body>
    <Probe xmlns="http://schemas.xmlsoap.org/ws/2005/04/discovery">
        <d:Types xmlns:d="http://schemas.xmlsoap.org/ws/2005/04/discovery" xmlns:dp0="http://www.onvif.org/ver10/network/wsdl">dp0:NetworkVideoTransmitter</d:Types>
        <Duration xmlns="http://schemas.microsoft.com/ws/2008/06/discovery">PT10S</Duration>
    </Probe>
</s:Body>

关于这里发生的事情的任何想法-为什么我们的应用程序看不到对发现请求的响应?

0 个答案:

没有答案