3

I'm completely stuck with ONVIF authentication. I think I've tried everything or at least almost everything and I don't find enough information on the Internet. I have created the stub client using svcutil, my code to do the authentication is (one of them because I have tried a lot of things):

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

After this there is the following error:

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

I will be very, very grateful if you please could help me with any information to solve this.

agamesh
  • 559
  • 1
  • 10
  • 26
Nely
  • 31
  • 1
  • 3
  • please check http://stackoverflow.com/questions/18149866/unable-to-connect-to-onvif-enabled-camera-using-c-sharp/18623888#18623888 – mhcuervo Sep 10 '13 at 04:56

2 Answers2

1

Try this way:

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

Notice that it is important to set ServicePointManager.Expect100Continue to false.

mhcuervo
  • 2,610
  • 22
  • 33
0

A couple of things could cause this:

  1. You've set a root password via web browser, thus locking the ONVIF user. Log in to the camera and add an ONVIF user (There's a special page for that)

  2. Your password digest includes only the password, where it should include a concatenation of a random nonce, the creation time, and the password.

  3. Your local clock is not synchronized with the camera's clock. call getSystemDateAndTime to read the remote clock and record the time differences between you.

These were the 3 out of the 4 major things that slowed me down (the 4th one was importing the wsdl, but it looks like you got it already)

Shloim
  • 5,281
  • 21
  • 36