ONVIF – 设备发现的开始

我打算做一个java onvif应用程序。 我创建了一个新项目并从devicemgmt.wsdl生成了源。还从远程discovery.wsdl生成了类。 如何使用生成的类发现网络中的设备? 谢谢你的帮助。

devicemgmt.wsdl与发现过程无关,ONVIF发现过程基于http://specs.xmlsoap.org/ws/2005/04/discovery它使用SOAP over UDP。

如果您使用的是apache-cxf,则可以使用

org.apache.cxf.ws.discovery.WSDiscoveryClient

一个简单的示例代码可能是:

import java.util.List; import javax.xml.ws.EndpointReference; import org.apache.cxf.ws.discovery.WSDiscoveryClient; public class Main { public static void main(String[] args) { WSDiscoveryClient client = new WSDiscoveryClient(); client.setVersion10(); // use WS-discovery 1.0 client.setDefaultProbeTimeout(1000); // timeout 1s System.out.println("Probe:" + client.getAddress()); List references = client.probe(); System.out.println("Nb answsers:" + references.size()); for (EndpointReference ref : references) { System.out.println(ref.toString()); } } } 

我有同样的问题,CXF只是很大,请检查我的方法: https ://github.com/thhart/javaWsDiscovery上的JavaWsDiscovery。

它使用Onvif标准建议的简单网络探测器来识别本地网络上的任何设备,以下行将返回所有可用设备:

final Collection urls = DeviceDiscovery.discoverWsDevicesAsUrls("^http$", ". onvif. ");