Detecting the State of Office Communications Server
Author: Rui Maximo
Publication date: November 2009
Product version: Microsoft Office Communications Server 2007 R2
Because your UCMA application depends on Office Communications Server, you might want your UCMA application to determine whether Office Communications Server stopped or is no longer responsive. This is especially important if your application runs as a service. It is valuable to provide feedback to the IT administrator by writing an event to the Application log in Event Viewer that explains that your application cannot connect to Office Communications Server because Office Communications Server is unresponsive. To determine the state of Office Communications Server, your application must perform an activity similar to a heartbeat monitor.
To implement a heartbeat monitoring solution to determine whether Office Communications Server is still running or stopped, Adarsh Khare, a software design engineer on the UCMA team, suggests using the StateChanged event, which sends the status of Office Communications Server every 30 minutes.
This solution requires registering to the local endpoint’s StateChanged event. Before you can subscribe to the StateChanged event, you must set up the necessary UCMA plumbing. This involves creating a collaboration platform and an application endpoint. After the application endpoint is created, the StateChanged event can then be subscribed to as shown in the following code example.
// Subscribe to StateChanged event
_applicationEndpoint.StateChanged += new EventHandler<LocalEndpointStateChangedEventArgs>(ApplicationEndpointStateChanged);
This registers the callback, ApplicationEndpointStateChanged, that UCMA 2.0 will call to notify your application of the status of Office Communications Server.
Now that the callback function, ApplicationEndpointStateChanged, is registered, you can implement this method. The following code example shows an implementation of this function that logs a message to the Application log. You will have to decide how you want your application to behave when Office Communications Server becomes unavailable, and then implement that logic in this callback.
// Event handler callback
private void ApplicationEndpointStateChanged(object sender, LocalEndpointStateChangedEventArgs e)
{
String _state = e.State + ": Office Communications Server is not responsive.";
logger.WriteEntry(_state, EventLogEntryType.Warning);
If(e.State == LocalEndpointState.Reestablishing)
{
//Endpoint trying to recover from connection failure
}
If(e.State == LocalEndpointState.Terminating)
{
//Fatal failure or application is terminating the endpoint or platform
}
}
Finally, before you stop the application endpoint and exit your application, you should unregister this event as shown in the following code example.
// Unregister event handler
_applicationEndpoint.StateChanged -= ApplicationEndpointStateChanged;
Monitoring the status of Office Communications Server will make your application more resilient to failures caused by Office Communications Server, and you will be able to provide a better user experience.
Office Communications Server Developer Resources
Portals
Office Communications Developer Center https://msdn.microsoft.com/ocdev
Unified Communications Developer Center https://go.microsoft.com/fwlink/?LinkID=133626
Documentation
Communications Server 2007 R2 Server SDK Documentation https://go.microsoft.com/fwlink/?LinkID=133566
MSDN Documentation portal for Communications Server 2007 R2 https://go.microsoft.com/fwlink/?LinkID=133592
Communicator 2007 and Communicator 2007 R2 documentation https://go.microsoft.com/fwlink/?LinkID=133593
MSDN Office http://twitter.com/MSDN_Office
Office Communications Server 2007 R2 http://twitter.com/DrRez
Developer Sandbox
- GotUC.Net developer resource for Office Communications Server http://gotuc.net
Forums
Office Communications Server https://go.microsoft.com/fwlink/?LinkId=177722
Unified Communications Integration https://go.microsoft.com/fwlink/?LinkId=177723
Office Communicator https://go.microsoft.com/fwlink/?LinkId=177724
Unified Communications Managed API SDK Forum https://go.microsoft.com/fwlink/?LinkId=177725