尝试将ONVIF网络服务与C#一起使用,没有参数的方法有效,其他方法无法使用"bad request"或"closed unexpectedly"



对GetSystemDateAndTime的调用有效。

对 GetDeviceInformation 的调用给出了错误的请求。

WSDL 是: https://www.onvif.org/ver10/device/wsdl/devicemgmt.wsdl

我已经尝试了很多事情,但错误消息没有帮助...另一个应用程序似乎成功访问了相机,但我无法从源代码中弄清楚他们是如何做到的:https://sourceforge.net/projects/onvifdm/

但既然他们能做到,我相信一定有办法......或者至少是一种确定我的代码失败的原因及其工作的方法,非常感谢任何帮助。

代码是:

Binding binding;
HttpTransportBindingElement httpTransportBindingElement = new HttpTransportBindingElement();
httpTransportBindingElement.AuthenticationScheme = AuthenticationSchemes.Digest;
binding = new CustomBinding(new TextMessageEncodingBindingElement(MessageVersion.Soap12WSAddressing10, Encoding.UTF8), httpTransportBindingElement);
DeviceClient deviceClient = new DeviceClient(binding, new EndpointAddress("http://192.168.0.15/onvif/device_service"));
deviceClient.ClientCredentials.HttpDigest.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation;
deviceClient.ClientCredentials.HttpDigest.ClientCredential.UserName = "username";
deviceClient.ClientCredentials.HttpDigest.ClientCredential.Password = "password";
var x = deviceClient.GetSystemDateAndTime();
var x2 = deviceClient.GetDeviceInformation(out string model, out string firmwareversion, out string serialnumber, out string hardwareId);

如果客户端和服务器之间的时间超出一定范围,通常只有几秒钟,我就会发生这种情况。确保两者都使用相同的 NTP 服务器,这可能会解决问题。

一些客户端通过在其他消息的请求中使用来自 GetSystemDataAndTime 调用的时间戳来绕过此检查来解决此问题。

在某些相机上,也可以关闭严格的检查

最新更新