且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何生成GetSystemDateAndTime xml

更新时间:2023-09-29 12:55:46

此错误表示尝试读取消息时遇到麻烦,所以我很难理解这可能是由于某种编码导致的.

This error is saying that there is trouble when trying to read a message, so i tough it was probably due to some sort of encoding ...

我是对的!

我要做的就是在TextMessageEncodingBindingElement的创建过程中更改参数.

All I had to do was changing a parameter in the TextMessageEncodingBindingElement's creation.

MessageVersion = MessageVersion.CreateVersion(EnvelopeVersion.Soap12, AddressingVersion.WSAddressing10)

您需要做的就是确保您具有良好的编码 AuthenticationScheme ...

All you need to do is make sure that you have good encoding and AuthenticationScheme...

这是我的最后一个代码,用于获取onvif摄像机(此处为cohuHD摄像机)的系统以及日期和时间设置:

Here's my final code to get an onvif camera's (here cohuHD camera) system and date and time settings:

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

奖金:

如果要执行需要凭证的功能,可以将其添加到deviceClient中,如下所示:

If you want to execute a function that needs credentials, you can add those to your deviceClient like so:

//DIGEST (httpBinding)
deviceClient.ClientCredentials.HttpDigest.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation;
deviceClient.ClientCredentials.HttpDigest.ClientCredential.UserName = userName;
deviceClient.ClientCredentials.HttpDigest.ClientCredential.Password = password;

还要提防EndpointAddress'URL ...我认为有些相机会使用Device_service和其他device_service.

Watch out also for the EndpointAddress' URL... I think some cameras use Device_service and other device_service .