我试图与ONVIF摄像机建立通信,但是由于缺乏Web服务,ONVIF和C#的经验,我遇到了一些我无法完全理解的奇怪错误。我在.NET 4.0上并使用Visual Studios 2010
EndpointAddress endPointAddress = new EndpointAddress("http://192.168.3.246:80/onvif/device_service");
WSHttpBinding bind = new WSHttpBinding();
bind.Security.Mode = SecurityMode.Message;
bind.Security.Message.ClientCredentialType = MessageCredentialType.UserName;
DeviceClient temp = new DeviceClient(bind, endPointAddress);
temp.ClientCredentials.UserName.UserName = myusername;
temp.ClientCredentials.UserName.Password = mypassword;
SystemDateTime s = temp.GetSystemDateAndTime();
这导致erorr崩溃“必须理解但无法处理元素'a:Action'中的数据”。我试图手动捕获请求并在
"s:mustUnderstand="1
“标志关闭的情况下执行该请求,但是随后出现“方法't:RequestSecurityToken
'未实现:方法名称或命名空间未被识别”错误。我的
ONVIF
相机是否有故障,或者我做错了什么?自三天以来,我一直在尝试各种方法来尝试连接到该摄像机,而不仅仅是诸如GetSystemDateAndTime
()和GetDeviceInformation
()之类的简单,不安全的信息,但我遇到了麻烦。 最佳答案
好吧,我希望它能像往常一样帮助其他人:
HttpTransportBindingElement httpBinding = new HttpTransportBindingElement();
httpBinding.AuthenticationScheme = AuthenticationSchemes.Digest;
var messegeElement = new TextMessageEncodingBindingElement();
messegeElement.MessageVersion = MessageVersion.CreateVersion(EnvelopeVersion.Soap12, AddressingVersion.None);
CustomBinding bind = new CustomBinding(messegeElement, httpBinding);
// Add our custom behavior - this require the Microsoft WSE 3.0 SDK
PasswordDigestBehavior behavior = new PasswordDigestBehavior(CameraASCIIStringLogin, CameraASCIIStringPassword);
DeviceClient client = new DeviceClient(bind, serviceAddress);
client.Endpoint.Behaviors.Add(behavior);
// We can now ask informations
client.GetSystemDateAndTime();
client.GetNetworkInterfaces();
client.GetScopes();
client.GetRelayOutputs();
client.GetWsdlUrl();
秘诀是在messegeElement中设置正确的信封设置(Soap12,因为我们的相机仅支持AdressingVersion.None来删除“ mustunderstand”标志),并且即使我在.NET 4.0上也将Microsoft WSE 3.0添加为库。并使用Visual Studio2010。这将使您能够使用它们提供的UserNameToken函数,而不必从头开始重新创建它们。
关于c# - 必须理解'a:Action',但无法处理,并且ONVIF摄像机上的RequestSecurityToken问题,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/5646534/