Notification Services—Creating a Notification Services Instance and Application
Microsoft .NET Framework, ASP.NET, Visual C# (CSharp, C Sharp, C-Sharp) Developer Training, Visual Studio
Creating a Notification Services Instance and Application
The Notification Services instance named StockWatch and a Notification Services
application named StockWatchApp are created in the Main( ) method of Example 18-1.
The code follows—the code that creates the Notification Services instance and application is highlighted:
static void Main(string[] args) { Server server = new Server("(local)"); // create a new instance NotificationServices ns = server.NotificationServices; nsi = new Instance(ns, "StockWatch"); CreateDeliveryChannel( ); // create a new application // in the StockWatch instance a = new Application(nsi, "StockWatchApp"); a.BaseDirectoryPath = baseDirectoryPath; CreateEventClass( ); CreateSubscriptionClass( ); CreateNotificationClass( ); CreateHostedEventProvider( ); CreateGenerator( ); CreateDistributor( ); CreateVacuumSchedule( ); a.QuantumDuration = new TimeSpan(0, 0, 15); a.PerformanceQueryInterval = new TimeSpan(0, 0, 5); a.SubscriptionQuantumLimit = 1; a.ChronicleQuantumLimit = 1; a.VacuumRetentionAge = new TimeSpan(0, 0, 1); nsi.Applications.Add(a); Console.WriteLine("Added application."); nsi.Create( ); nsi.RegisterLocal(serviceUserName, servicePassword); nsi.Enable( ); Console.WriteLine("Application enabled." + Environment.NewLine); CreateSubscriber( ); CreateSubscription( ); Console.WriteLine(Environment.NewLine + "Press any key to continue."); Console.ReadKey( ); }

Figure 18-8. StockWatch notification email
The NotificationServices object represents a Notification Services server. The
Instances property of the NotificationServices class returns an InstanceCollection
object containing a collection of Notification Services instances as Instance objects. At a
minimum, you must define a DeliveryChannel object and an Application object to create
an Instance object—in this example, this is done by the CreateDeliveryChannel( )
and Main( ) methods.
The RegisterLocal( ) method of the Instance class registers an instance of Notification Services on the local computer. This is the same as registering a Notification Services
instance using SQL Server Management Studio by right-clicking the
Notification Services instance and selecting Tasks -> Register from the context menu.
You can also register a Notification Services instance by using the nscontrol register
command. Registering an instance creates or updates registry entries for the instance,
creates performance counters, and optionally creates a Windows Service to run the
instance.
The Enable( ) method of the Instance class enables all instance and application components,
allowing event collection, notification generation, notification distribution,
and subscription management. A NotificationServices instance is disabled when
you create it.
The NMO classes used to manage Notification Services instances are described in Table 18-1.
Table 18-1. NMO classes for managing Notification Services instances
| Class | Description |
Instance
| Represents a Notification Services instance. |
InstanceCollection
| Represents a collection of instances as Instance objects. The Instances property of the NotificationServices class returns the Notification Services instances on the server.
|
The Application object represents a Notification Services application. At a minimum,
you must define a Generator object and a Distributor object for an
Application object—in this example, this is done by the CreateGenerator( ) and
CreateDistributor( ) methods.
This example configures the Application object by setting the following properties:
The NMO classes used to manage Notification Services applications are described in Table 18-2.
Table 18-2. NMO classes for managing applications
| Class | Description |
Application
| Represents a Notification Services application. |
ApplicationCollection
| Represents a collection of Notification Services applications as Application objects. The Applications property of the Instance class returns the Notification Services applications hosted on the Notification Services instance.
|
|

