【问题标题】:How to generate GetSystemDateAndTime xml如何生成 GetSystemDateAndTime xml
【发布时间】:2018-05-09 03:26:27
【问题描述】:

我有以下从this source 获取的代码...

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

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

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

            CustomBinding bind = new CustomBinding(messageElement, httpBinding);


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

            var profs = mediaClient.GetProfiles();

            //rest of the code...

当我在调试器中通过GetProfiles() 部分运行wireshark 时,我看到生成的XML 如下所示:

需要什么代码才能将 xml 更改为如下所示:

我应该如何调用GetSystemDateAndTime 函数?

要调用GetProfiles 函数,我必须创建一个MediaClient,然后调用该函数...

是否有 MediaClient 之类的东西可以访问 GetSystemDateAndTime??

编辑:

我发现您可以使用DeviceClient 来访问GetSystemDateAndTime 函数...

您需要先将设备管理 wsdl 添加到您连接的服务中: https://www.onvif.org/ver10/device/wsdl/devicemgmt.wsdl

我还在那里添加了System.Net.ServicePointManager.Expect100Continue = false;,因为我看到有人在this link 上说它有帮助...

所以我补充说:

CustomBinding bind = new CustomBinding(messageElement, httpBinding);
System.Net.ServicePointManager.Expect100Continue = false;
DeviceClient d = new DeviceClient(bind, new EndpointAddress($"http://{cameraAddress}/onvif/device_service"));
var time = d.GetSystemDateAndTime();

注意: 我仍然收到错误消息:

        ErrorMessage    "The header 'To' from the namespace 'http://www.w3.org/2005/08/addressing' was not understood by the recipient of this message, causing the message to not be processed.  This error typically indicates that the sender of this message has enabled a communication protocol that the receiver cannot process.  Please ensure that the configuration of the client's binding is consistent with the service's binding. "   string

【问题讨论】:

    标签: c# wsdl visual-studio-2017 onvif


    【解决方案1】:

    这个错误表示尝试阅读消息时出现问题,所以我认为这可能是由于某种编码......

    我是对的!!

    我所要做的就是在 TextMessageEncodingBindingElement 的创建中更改一个参数。

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

    您需要做的就是确保您拥有良好的encodingAuthenticationScheme...

    这是我获取 onvif 相机(此处为 cohuHD 相机)系统以及日期和时间设置的最终代码:

    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 中:

    //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。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-04-19
      • 1970-01-01
      • 1970-01-01
      • 2013-07-25
      • 2023-04-04
      • 1970-01-01
      • 1970-01-01
      • 2015-01-31
      相关资源
      最近更新 更多