3

我完全坚持使用ONVIF身份验证。我想我已经尝试了所有方法或至少几乎所有方法,但我在 Internet 上找不到足够的信息。我已经使用 svcutil 创建了存根客户端,我进行身份验证的代码是(其中之一是因为我尝试了很多东西):

 string uri = "http://140.0.22.39/onvif/services";

 EndpointAddress serviceAddressPrueba = new EndpointAddress(uri);
 HttpTransportBindingElement httpBinding = new HttpTransportBindingElement();
 httpBinding.AuthenticationScheme = AuthenticationSchemes.Digest;
 var messegeElement = new TextMessageEncodingBindingElement();
 messegeElement.MessageVersion = MessageVersion.CreateVersion(EnvelopeVersion.Soap12, AddressingVersion.None);
CustomBinding bindprueba = new CustomBinding(messegeElement, httpBinding);
DeviceClient clientprueba = new DeviceClient(bindprueba, serviceAddressPrueba);
string passwordDigestBase64;
//HERE I PUT THE CODE TO ENCRYPT THE PASSWORD.
PasswordDigestBehavior behavior1 = new PasswordDigestBehavior("root",passwordDigestBase64);
clientprueba.Endpoint.Behaviors.Add(behavior1);
string d1;
string d2;
string d3;
string d4;

clientprueba.GetDeviceInformation(out d1, out d2, out d3, out d4);

在此之后有以下错误:

{"The remote server returned an unexpected response: (400) Bad Request."}

如果您能帮助我提供任何信息来解决这个问题,我将非常非常感激。

4

2 回答 2

1

试试这个方法:

ServicePointManager.Expect100Continue = false;
var endPointAddress = new EndpointAddress("http://" + cameraAddress + "/onvif/device_service");
var httpTransportBinding = new HttpTransportBindingElement { AuthenticationScheme = AuthenticationSchemes.Digest };
var textMessageEncodingBinding = new TextMessageEncodingBindingElement { MessageVersion = MessageVersion.CreateVersion(EnvelopeVersion.Soap12, AddressingVersion.None) };
var customBinding = new CustomBinding(textMessageEncodingBinding, httpTransportBinding);
var passwordDigestBehavior = new PasswordDigestBehavior(adminName, adminPassword);
var deviceClient = new DeviceClient(customBinding, endPointAddress);
deviceClient.Endpoint.Behaviors.Add(passwordDigestBehavior);

ServicePointManager.Expect100Continue请注意,设置为很重要false

于 2013-12-21T15:41:33.997 回答
0

有几件事可能会导致这种情况:

  1. 您已通过 Web 浏览器设置了 root 密码,从而锁定了 ONVIF 用户。登录摄像头并添加 ONVIF 用户(有专门的页面)

  2. 您的密码摘要仅包含密码,其中应包含随机数、创建时间和密码的串联。

  3. 您的本地时钟与相机的时钟不同步。调用 getSystemDateAndTime 读取远程时钟并记录你们之间的时差。

这些是让我慢下来的 4 件主要事情中的 3 件(第四件是导入 wsdl,但看起来你已经掌握了)

于 2012-05-03T11:55:18.630 回答