2

CONTEXT:

I'm currently trying to code a C# application to get informations, such as camera feed, dateTime, streaming URL, profiles and much more, from an ip camera, using the ONVIF "standard"...

I managed to get the system time of the camera using this bit of code:

public bool Initialise(string cameraAddress, string userName, string password)
{
    bool result = false;

    try
    {
        var messageElement = new TextMessageEncodingBindingElement()
        {
            MessageVersion = MessageVersion.CreateVersion(EnvelopeVersion.Soap12, AddressingVersion.WSAddressing10)
        };

        HttpTransportBindingElement httpBinding = new HttpTransportBindingElement()
        {
            AuthenticationScheme = AuthenticationSchemes.Digest
        };

        CustomBinding bind = new CustomBinding(messageElement, httpBinding);

        System.Net.ServicePointManager.Expect100Continue = false;

        DeviceClient deviceClient = new DeviceClient(bind, new EndpointAddress($"http://{cameraAddress}/onvif/device_service"));

        var temps = deviceClient.GetSystemDateAndTime();
    }
    catch (Exception ex)
    {
        ErrorMessage = ex.Message;
    }
    return result;
}

The deviceClient.GetSystemDateAndTime() function is posting this XML/SOAP envelope through http: img0

I'm reading this XML from wireshark when i run the function through VS2017 debugger...

Guess: I'm trying to add a UsernameToken type of authentication to my code so I can do operations that need this type of authentication...

Here's a picture of a working XML/SOAP envelope that i would like to achieve: img1

I tried to add these lines to my code:

deviceClient = new DeviceClient(bind, new EndpointAddress($"http://{cameraAddress}/onvif/device_service"));
deviceClient.ClientCredentials.HttpDigest.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation;
deviceClient.ClientCredentials.HttpDigest.ClientCredential.UserName = userName;
deviceClient.ClientCredentials.HttpDigest.ClientCredential.Password = password;

,but it doesn't even add a user/password bit to the XML I'm sending....

QUESTION: How can I add this usernameToken to the header of the XML/SOAP envelope I'm sending?

LoukMouk
  • 483
  • 7
  • 21

0 Answers0