使用 Visual Studios 2010 在 .NET 4.0 中进行 ONVIF 身份验证
我的任务是尝试与建筑物中的 ONVIF 摄像机建立通信,最终升级公司的家庭自动化解决方案,以自动识别 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 - 错误请求”错误,根据我所读到的内容,这是因为我需要处理相机的身份验证。
问题是,我发现的有关 WS-Security(似乎由 ONVIF 使用)的所有内容都非常非常混乱,有很多不同的解决方案,但没有什么真正对我有用。例如,这篇文章听起来非常简单,但我尝试创建 UserNameSecurityToken 但仍然收到 400 错误请求错误。因为我不知道这是否是因为我写错了令牌系统,是否是因为相机不支持我尝试做的事情。
我已经尝试过 WSHttpBinding 并将其置于用户名模式,但是使用 WSHttpBinding 破坏了我能够创建的基本信息发现(带有 MustUnderstand 错误)...
对我有什么指示吗?简单的WS-Security/.NET、C#/ONVIF教程,一切都会接受。
My task is to try to establish a communication with a ONVIF camera in the building to, eventually, upgrade the company's domotic solution to automatically recognize ONVIF cameras and to be able to set them up and to use their services.
I am already able to gather some basic informations like its model, its MAC address and its firmware version this way:
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]);
I have this xml specification for the customBinding in my app.config file:
<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>
My problem is that it's impossible for me to go deeper into what I can ask the camera. I get "400 - Bad request" errors for anything I try, and according to what I have read it's because I need to handle authentication for the camera.
The problem is that, everything I find about WS-Security (which seems to be used by the ONVIF) is really, really confused, with a lot of different solutions, and nothing really working for me. For example, this post here make it sound very simple, but I've tried to create a UserNameSecurityToken and I still get 400 bad request errors. Since I don't know if that's because I've written my Token system wrong, if it's because the camera doesn't support what I try to do.
I've already tried WSHttpBinding and putting it in Username mode, but using WSHttpBinding break the basic information discovery I was able to create (with a MustUnderstand error)...
Any pointers for me? Simple WS-Security/.NET, C#/ONVIF tutorials, everything will be accepted.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧:
问题是相机在提供除最简单信息之外的任何信息之前都需要进行身份验证,而最棘手的部分是最终捕获有效的 xml onvif 消息以在我自己的软件中重新创建它。
All right:
The problem was that the camera required authentication before giving any information beyond the simplest ones, and the trickiest part was to finally catch a working xml onvif message to recreate it in my own software.