我的任务是尝试与建筑物中的 ONVIF 摄像头建立通信,最终升级公司的 domotic 解决方案,以自动识别 ONVIF 摄像头并能够设置它们并使用它们的服务。
我已经能够通过这种方式收集一些基本信息,比如它的型号、MAC 地址和固件版本:
EndpointAddress endPointAddress = new EndpointAddress("<mycameraurl:<mycameraport>/onvif/device_service");
CustomBinding bind = new CustomBinding("DeviceBinding");
DeviceClient temp = new DeviceClient(bind, endPointAddress);
String[] arrayString = new String[4];
String res = temp.GetDeviceInformation(out arrayString[0], out arrayString[1], out arrayString[2], out arrayString[3]);
MessageBox.Show("Model " + arrayString[0] + ", FirmwareVersion " + arrayString[1] + ", SerialNumber " + arrayString[2] + ", HardwareId " + arrayString[3]);
我的 app.config 文件中有 customBinding 的这个 xml 规范:
<customBinding>
<binding name="DeviceBinding">
<textMessageEncoding maxReadPoolSize="64" maxWritePoolSize="16"
messageVersion="Soap12" writeEncoding="utf-8">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
</textMessageEncoding>
<httpTransport manualAddressing="false" maxBufferPoolSize="524288"
maxReceivedMessageSize="65536" allowCookies="false" authenticationScheme="Anonymous"
bypassProxyOnLocal="false" decompressionEnabled="true" hostNameComparisonMode="StrongWildcard"
keepAliveEnabled="false" maxBufferSize="65536" proxyAuthenticationScheme="Anonymous"
realm="" transferMode="Buffered" unsafeConnectionNtlmAuthentication="false"
useDefaultWebProxy="true" />
</binding>
</customBinding>
我的问题是我不可能更深入地了解我可以问相机什么。对于我尝试的任何内容,我都会收到“400 - Bad request”错误,根据我所阅读的内容,这是因为我需要处理相机的身份验证。
问题是,我发现的关于 WS-Security(似乎被 ONVIF 使用)的所有内容都非常非常混乱,有很多不同的解决方案,但没有什么对我真正有用。例如,这里的这篇文章听起来很简单,但我尝试创建一个 UserNameSecurityToken ,但仍然收到 400 错误请求错误。因为我不知道这是否是因为我的令牌系统写错了,如果是因为相机不支持我尝试做的事情。
我已经尝试过 WSHttpBinding 并将其置于用户名模式,但是使用 WSHttpBinding 破坏了我能够创建的基本信息发现(带有 MustUnderstand 错误)......
对我有什么指示吗?简单的 WS-Security/.NET、C#/ONVIF 教程,一切都会被接受。