Registering a SIP Application with Office Communications Server

This content is no longer actively maintained. It is provided as is, for anyone who may still be using these technologies, with no warranties or claims of accuracy with regard to the most recent product version or service release.

Registering a SIP Application with Office Communications Server

The following managed code sample registers a MSFT_SIPApplicationSetting object for a SIP application that will run on Office Communications Server. This object contains the information used by WMI to identify a SIP application on the server.

The application is registered if a corresponding MSFT_SIPApplicationSetting entry with the same URI is present in the WMI repository. The URI of the application is defined in the application manifest of the SIP application. If an application is not successfully registered (a corresponding WMI entry was not created), the application will not connect to the Office Communications Server.

Script-only (MSPL) applications are installed through the Microsoft Management Console (MMC), rather than WMI directly.

C#

using System;
using System.Management;

namespace SIPSetup
{

class AppRegisterObj
{
// ManagementObject that contains the specific configuration for
// the MSFT_SIPApplicationSetting instance
private ManagementObject _appSetting;

// Contains the unique URI as defined in the application manifest
private string _uri;
// Public read-only property for the URI
public string Uri
{
get
{
return _uri;
}
}

// Public constructor for the AppRegisterObj class
// Parameters:
//  -- instanceId: System.Guid object that specifies the Instance ID of the
// MSFT_SIPApplicationSetting object
//  -- uri: string value that specifies the unique URI of the object
//  -- name: string value that specifies the friendly name of the object
//  -- isEnabled: true if this application will run; false if it will not
//  -- isCritical: true if application failure should shut down the Office Communications Server;
//       false if it should not
//  -- scriptPath: optional path to script if application is script-only; use the
// empty string "" if not applicable
//  Return value: void
public AppRegisterObj(
Guid instanceID,
string uri,
string name,
bool isEnabled,
bool isCritical,
string scriptPath
)
{
// Create an instance of the System.Management.ManagementClass class configured
// for MSFT_SIPApplicationSetting.
ManagementClassappSettingClass = new ManagementClass(
"root/cimv2",  // WMI repository
"MSFT_SIPApplicationSetting", // WMI class type
new ObjectGetOptions() // empty ObjectGetOptions object
);

// Set the _uri field of this object to the supplied URI.
_uri = uri;

// Create an instance of the MSFT_SIPApplicationSetting class using the
// configuration supplied to appSettingClass and assign it to the
// private _appSetting field of this AppRegisterObj instance.
_appSetting = appSettingClass.CreateInstance();

// Populate the properties using the parameters supplied to
// the constructor.
_appSetting["InstanceID"] = "{" + instanceID.ToString() + "}";
_appSetting["URI"] = _uri;
_appSetting["Name"] = name;
_appSetting["Enabled"] = (isEnabled == true) ?
"TRUE" : "FALSE";
_appSetting["Critical"] = (isCritical == true) ?
"TRUE" : "FALSE";

// Check for the empty string; if it is not empty, a
// script path is used and must be assigned to the "ScriptPath"
// property.
if (scriptPath != "")
{
_appSetting["ScriptPath"] = scriptPath;
}

}

// Register the object with WMI.
public void Register()
{
try
{
_appSetting.Put();
Console.WriteLine("Application [{0}] was successfully registered!", _uri);
}
catch (Exception e)
{
Console.WriteLine("Exception thrown: {0}", e.Message);
}

}

// Unregister the object with WMI.
public void Unregister()
{
try
{
_appSetting.Delete();
Console.WriteLine("Application [{0}] was successfully unregistered!", _uri);
}
catch (Exception e)
{
Console.WriteLine("Exception thrown: {0}", e.Message);
}

}

// Object entry point
public static void Main()
{
// Create an instance of AppRegisterObj.
AppRegisterObj myAppRegisterObj = new AppRegisterObj(
Guid.NewGuid(),
"http://my.domain.com/myAppName",
"My SIP Application",
true,
false,
""
);

// Register this new instance.
myAppRegisterObj.Register();

// Unregister this new instance.
myAppRegisterObj.Unregister();

}

}

}

VB.NET

Imports System
Imports System.Management

Class AppRegisterObj

    '  ManagementObject that contains the specific configuration for
    '  the MSFT_SIPApplicationSetting instance
   Private AppSetting As ManagementObject
 '  Contains the unique URI as defined in the application manifest
   Public Uri As String
    '  Public constructor for the AppRegisterObj class
'  Parameters:
'   -- instanceId: System.Guid object that specifies the Instance ID of the
'  MSFT_SIPApplicationSetting object
'   -- uri: string value that specifies the unique URI of the object
'   -- name: string value that specifies the friendly name of the object
'   -- isEnabled: true if this application will run; false if it will not
'   -- isCritical: true if application failure should shut down Office Communications Server;
'        false if not
'   -- scriptPath: optional path to script if application is script-only; use the
'    empty string "" if not applicable
'   Return value: void
   Public Sub New(instanceID As System.Guid, uri As String, name As String, isEnabled As Boolean,
      isCritical As Boolean, scriptPath As String)
'  Create an instance of the System.Management.ManagementClass class configured
'  for MSFT_SIPApplicationSetting.
      Dim appSettingClass As New ManagementClass("root/cimv2", "MSFT_SIPApplicationSetting",
         New ObjectGetOptions())
        '  Set the _uri field of this object to the supplied URI.
      Uri = uri
'  Create an instance of the MSFT_SIPApplicationSetting class using the
'  configuration supplied to appSettingClass and assign it to the
'  private _appSetting field of this AppRegisterObj instance.
      AppSetting = appSettingClass.CreateInstance()
      '  Populate the properties using the parameters supplied to
'  the constructor.
      AppSetting("InstanceID") = "{" + instanceID.ToString() + "}" ' Curly braces necessary
      AppSetting("URI") = Uri
      AppSetting("Name") = name

      If isEnabled = True
         AppSetting("Enabled") = "TRUE"
      Else
         AppSetting("Enabled") = "FALSE"
      End If

      If isCritical = True
         AppSetting("Critical") = "TRUE"
      Else
         AppSetting("Critical") = "FALSE"
      End If
        '  Check for the empty string; if it is not empty, a
'  script path is used and must be assigned to the "ScriptPath"
'  property.
      If scriptPath <> "" Then
         AppSetting("ScriptPath") = scriptPath
      End If

   End Sub ' New

   ' Register the object with WMI.
   Public Sub Register()

      Try
         AppSetting.Put()
         Console.WriteLine("Application [{0}] was successfully registered!", Uri)
      Catch e As Exception
         Console.WriteLine("Exception thrown: {0}", e.Message)
      End Try

   End Sub 'Register

   ' Unregister the object with WMI.
   Public Sub Unregister()

      Try
         AppSetting.Delete()
         Console.WriteLine("Application [{0}] was successfully unregistered!", Uri)
      Catch e As Exception
         Console.WriteLine("Exception thrown: {0}", e.Message)
      End Try

   End Sub 'Unregister


   Public Shared Sub Main()

      ' Create an instance of AppRegisterObj with the supplied parameters.
      Dim myAppRegisterObj As New AppRegisterObj(Guid.NewGuid(), "http: ' my.domain.com/myAppName",
        "My SIP Application", True, False, "")

      ' Register the new object.
      myAppRegisterObj.Register()

      ' Unregister the new object.
      myAppRegisterObj.Unregister()

   End Sub 'Main

End Class 'AppRegisterObj

For an unmanaged code sample using C++ and COM, see Registering a SIP Application (Unmanaged Code).