背景:
我目前正在尝试使用ONVIF"标准"来编码C#应用程序来获取信息,例如相机提要,日期时间,流媒体网址,配置文件等等。 ...
我设法使用这段代码获取相机的系统时间:
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.GetSystemDateAndTime()
函数通过http发布此XML / SOAP信封:
当我通过VS2017调试器运行该函数时,我正在从wireshark读取此XML ...
猜测: 我试图在我的代码中添加UsernameToken类型的身份验证,以便我可以执行需要此类身份验证的操作...
我尝试将这些行添加到我的代码中:
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;
,但它甚至没有为我发送的XML添加用户/密码位....
问题: 如何将此usernameToken添加到我发送的XML / SOAP信封的标题?