Developing a Custom Content Formatter

Notification Services provides a built-in content formatter based on Extensible Stylesheet Transformation Language (XSLT) to help you develop applications rapidly. However, if you want to format your notification data using other techniques, you must develop a custom content formatter.

IContentFormatter Interface

Content formatters are components that take notification data in raw form as input and return formatted notification messages. Content formatters are loaded by the distributor, which is hosted by the Notification Services engine. The distributor interacts with content formatters via an interface called IContentFormatter.

To develop a custom content formatter, you must develop a class that implements the IContentFormatter interface. This interface is available in the Microsoft.SqlServer.NotificationServices namespace.

The distributor calls the content formatter for each message that must be formatted. This message might be one notification, a digest of notifications, or the notification data for one multicast message.

The distributor first calls Initialize, then calls FormatContent for each message to be formatted, and, when the work item is complete, calls the Close method. The FormatContent method is not called again unless the Initialize method is first called.

If formatting fails, the FormatContent method can throw an exception. The distributor logs the exception to the Application log and marks the notification as failed. The failed notification is not sent to the delivery protocol. If the notification class is configured to retry notifications, the notification is picked up for formatting in the next retry interval.

The Initialize and Close methods should never throw exceptions.

You must implement your custom content formatter as a class in a managed code assembly. This assembly can reside anywhere that is accessible to the notification application.

Formatting Notifications

When the distributor initializes the content formatter by calling the Initialize method, it passes any declared arguments, and the digest delivery setting. The content formatter implementation should use these values to configure itself and store any settings that it will use. When the distributor invokes the content formatter to format a notification message, it calls the FormatContent method and passes an array of hash tables containing notification data to the content formatter. The notification data includes the subscriber locale and device type.

Depending on your application, your implementation of the content formatter may need to handle the formatting of digest notifications, multiple devices, and multiple locales.

Using a Custom Content Formatter

To use a custom content formatter, you must declare it in the application definition. When you declare a content formatter, you provide the class name, assembly name, and the names and values of any arguments required to initialize the content formatter. For more information, see Configuring Content Formatters.


Your custom content formatter runs with the same privileges as the distributor, which is run by the Notification Services engine. The account under which the Notification Services engine runs must have permission to access the assembly.

See Also


Security Considerations for Notification Services

Other Resources

XSLT Content Formatter
Developing Custom Notification Services Components

Help and Information

Getting SQL Server 2005 Assistance