We use ‘IsServerConnected’ and ‘IsLoggedIn’ to check the connection status before sending alarm via ‘PostMessage’.
When login expired, e.g. leave program a half day, ‘IsServerConnected’ and ‘IsLoggedIn’ return ‘false’ with Windows Authentication.
So our program can notice connection is closed.
But with Basic Authentication, those methods return ‘true’.
In failure case, there’s no way to detect ‘PostMessage’ calling failed.
But it seems that internal SOAP API returns correct status code.
Following image shows the result of ‘POST /Central/AlamServiceToken’.
Is this a bug that ‘IsServerConnected’ and ‘IsLoggedIn’ couldn’t return correct status?
Or is there a solution to get the result of ‘PostMessage’ calling failure.
The screendump is a dump of the AlarmServiceToken (supporting AlacommandToken SOAP) that is used for basic users.
Please note that the AlarmService (supporting AlarmCommand SOAP) is used for AD users.
The IsServerConnected are checking for the Management Server, but the Alarm handling is done in the Event Server.
I suggest you use the MessageCommunication client, as it communicates with the EventServer, and has a IsConnected flag (and event when state is changing).
I understand that we should check connection status between ClientApplication and EventServer before ‘Post/SendMessage’.
Followings are pseudo-code from our application.
Though you suggest to use 'MessageCommunication ', We couldn’t find good samples.
Could you kindly teach us how to check the prerequisite of sending alarm/event?
Uri mgtServerUri; // Management Server URI
CredentialCache credential;
///
/// Setup
VideoOS.Platform.SDK.Environment.Initialize();
if (basicAuth)
{
mgtServerUri = new Uri(string.Format("https://{0}:{1}", host, port));
credential = Util.BuildCredentialCache(mgtServerUri, user, password, "Basic");
}
else
{
mgtServerUri = new Uri(string.Format("http://{0}:{1}", host, port));
credential = Util.BuildCredentialCache(mgtServerUri, user, password, "Negotiate");
}
// Q: What kind of server should we add? Only management server?
VideoOS.Platform.SDK.Environment.AddServer(mgtServerUri, credential);
VideoOS.Platform.SDK.Environment.Login(mgtServerUri, false);
/// Q: Comes from alarm/message sample code, what purpose?
VideoOS.Platform.SDK.Environment.LoadConfiguration(mgtServerUri);
///
/// Send Alarm to Event Server
while(SendQueueIsNotEmpty)
{
/// Following call confirm the connection between ClientApplication and Managment Server.
/// So we don't need to confirm before Send/PostMessage since they need connection between ClientApplication and EventServer.
/// Is my understanding correct?
// if(
// !VideoOS.Platform.SDK.Environment.IsServerConnected(mgtServerUri) &&
// !VideoOS.Platform.SDK.Environment.IsLoggedIn(mgtServerUri))
// )
// {
// exit(1);
// }
/// Q: Usage of MessageCommunication is ambiguous. What is the meaning of 'MasterSite'?
//
// MessageCommunicationManager.Start(EnvironmentManager.Instance.MasterSite.ServerId);
// MessageCommunication messageCommunication = MessageCommunicationManager.Get(EnvironmentManager.Instance.MasterSite.ServerId);
// if(!messageCommunication.IsConnteced){ exit(1); }
/// Send Message or Post Message
// var result = EnvironmentManager.Instance.SendMessage(new Message(MessageId.Server.NewAlarmCommand) { Data = alarm });
EnvironmentManager.Instance.PostMessage(new Message(MessageId.Server.NewAlarmCommand) { Data = alarm });
}
///
/// Teardown
VideoOS.Platform.SDK.Environment.Logout(mgtServerUri);
VideoOS.Platform.SDK.Environment.RemoveAllServers();
VideoOS.Platform.SDK.Environment.UnInitialize();
I believe the LibraryEventGenerator does the same as what you are trying to do. In that sample there is no verification either.
An alternative approach could be to use iAlarmCommand Add method instead. AlarmClientWPF sample show how to use alarm command but does not use the Add method.
http://doc.developer.milestonesys.com/html/index.html?base=samples/alarmclientwpfsample.html&tree=tree_2.html
I feel our discussion is not on the same wavelength.
Let me explain original problems again.
Our program sends alarm/event to XProtect via `EnvironmentManager.Instance.PostMessage`.
For this, we call VideoOS.Platform.SDK.Environment for login.
But after a while, PostMessage begins to fail.
It seems login session is expired.
Our packet capture shows internal SOAP API return error code, but there’s no solution to detect this.
This is the problem.
When using the LibraryEventGenerator sample over a longer period of time, I am not able to reproduce your issue. I test with Corporate 2018 R2 and basic user. Can you provide a sample that we can use to re-create the issue?
I’m sorry that I didn’t inform enough information.
My colleague taght me 2 more prerequisite to reproduce the problem.
1. Our application runs as windows service, not standalone application.
2. It seems problem happens after Windows 10’s fast startup.
We’ll investigate further.
After investigation, we confirmed that problem happens after PC restart by using Windows 10’s fast startup feature.
It seems it cause some instability or status mismatch inside MIPSDK library.
We’ll solve problem by disabling fast startup feature.