开发者

'a:Action' must be understood but cannot be handled and RequestSecurityToken problem on an ONVIF Camera

I'm trying to establish a communication with an ONVIF camera, and I'm getting some strange errors that I can't fully comprehend due to my lack of experience with Web Services, ONVIF and C#. I'm on .NET 4.0 and using 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();

This lead to a crash with the erorr "The data in element 'a:Action' must be understood but cannot be handled". I've tried to manually catch the request and to execute it with the "s:mustUnderstand="1" flags turned off, but I then get an "Method 't:RequestSecurityToken' not implemented: method name or namespace not recognized" 开发者_开发问答error.

Is my ONVIF camera bugged, or am I doing something wrong ? I've been trying various things since 3 days to try to connect to that camera beyond simple, non-secured informations like GetSystemDateAndTime() and GetDeviceInformation(), but I'm stuck.


Allright, I hope it'll enventually help other people stuck like I was:

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();

The secret was to set the right envelope settings in messegeElement (Soap12 because our camera only support this, AdressingVersion.None to remove the "mustunderstand" flag) and to add the Microsoft WSE 3.0 as a library even if I'm on .NET 4.0 and using Visual Studio 2010. This will enable you to use their provided UserNameToken functions without having to re-create them yourself from scratch.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜