如何生成GetSystemDateAndTime xml [英] How to generate GetSystemDateAndTime xml
问题描述
我有以下代码来自这个来源 ...
I have the following bit of code that i took from 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看起来像:
When i run wireshark while going through the GetProfiles()
part in the debugger, I see that the generated XML looks like:
将xml更改为以下代码将需要什么代码:
What code would it take to change the xml to look like:
我应该如何调用GetSystemDateAndTime
函数?
要调用GetProfiles
函数,我必须创建一个MediaClient
,然后调用该函数...
To call the GetProfiles
function, I had to create a MediaClient
and, then, call that function...
是否有MediaClient之类的东西可以访问GetSystemDateAndTime?
Is there such thing as a MediaClient to get access to the GetSystemDateAndTime??
我发现您可以使用DeviceClient
来访问GetSystemDateAndTime
函数...
I found that you could use the DeviceClient
to get access the the GetSystemDateAndTime
function...
您需要先将设备管理wsdl添加到连接的服务中,然后再执行以下操作: https://www.onvif.org/ver10/device/wsdl/devicemgmt. wsdl
You'll need to add the device management wsdl to your connected services before: https://www.onvif.org/ver10/device/wsdl/devicemgmt.wsdl
我还在其中添加了System.Net.ServicePointManager.Expect100Continue = false;
,因为我看到有人说它对
I also added System.Net.ServicePointManager.Expect100Continue = false;
in there because i saw someone said it helped at 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
推荐答案
此错误表示尝试读取消息时遇到麻烦,所以我很难理解这可能是由于某种编码导致的.
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 .
这篇关于如何生成GetSystemDateAndTime xml的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!