- XML Reference Guide
- Overview
- What Is XML?
- Informit Articles and Sample Chapters
- Books and e-Books
- Official Documentation
- Table of Contents
- The Document Object Model
- Informit Articles and Sample Chapters
- Books and e-Books
- Official Documentation
- DOM and Java
- Informit Articles and Sample Chapters
- Books and e-Books
- Implementations
- DOM and JavaScript
- Using a Repeater
- Repeaters and XML
- Repeater Resources
- DOM and .NET
- Informit Articles and Sample Chapters
- Books and e-Books
- Documentation and Downloads
- DOM and C++
- DOM and C++ Resources
- DOM and Perl
- DOM and Perl Resources
- DOM and PHP
- DOM and PHP Resources
- DOM Level 3
- DOM Level 3 Core
- DOM Level 3 Load and Save
- DOM Level 3 XPath
- DOM Level 3 Validation
- Informit Articles and Sample Chapters
- Books and e-Books
- Documentation and Implementations
- The Simple API for XML (SAX)
- Informit Articles and Sample Chapters
- Books and e-Books
- Official Documentation
- SAX and Java
- Informit Articles and Sample Chapters
- Books and e-Books
- SAX and .NET
- Informit Articles and Sample Chapters
- SAX and Perl
- SAX and Perl Resources
- SAX and PHP
- SAX and PHP Resources
- Validation
- Informit Articles and Sample Chapters
- Books and e-Books
- Official Documentation
- Document Type Definitions (DTDs)
- Informit Articles and Sample Chapters
- Books and e-Books
- Official Documentation
- XML Schemas
- Informit Articles and Sample Chapters
- Books and e-Books
- Official Documentation
- RELAX NG
- Informit Articles and Sample Chapters
- Books and e-Books
- Official Documentation
- Schematron
- Official Documentation and Implementations
- Validation in Applications
- Informit Articles and Sample Chapters
- Books and e-Books
- XSL Transformations (XSLT)
- Informit Articles and Sample Chapters
- Books and e-Books
- Official Documentation
- XSLT in Java
- Java in XSLT Resources
- XSLT and RSS in .NET
- XSLT and RSS in .NET Resources
- XSL-FO
- Informit Articles and Sample Chapters
- Books and e-Books
- Official Documentation
- XPath
- Informit Articles and Sample Chapters
- Books and e-Books
- Official Documentation
- XML Base
- Informit Articles and Sample Chapters
- Official Documentation
- XHTML
- Informit Articles and Sample Chapters
- Books and e-Books
- Official Documentation
- XHTML 2.0
- Documentation
- Cascading Style Sheets
- Informit Articles and Sample Chapters
- Books and e-Books
- Official Documentation
- XUL
- XUL References
- XML Events
- XML Events Resources
- XML Data Binding
- Informit Articles and Sample Chapters
- Books and e-Books
- Specifications
- Implementations
- XML and Databases
- Informit Articles and Sample Chapters
- Books and e-Books
- Online Resources
- Official Documentation
- SQL Server and FOR XML
- Informit Articles and Sample Chapters
- Books and e-Books
- Documentation and Implementations
- Service Oriented Architecture
- Web Services
- Informit Articles and Sample Chapters
- Books and e-Books
- Official Documentation
- Creating a Perl Web Service Client
- SOAP::Lite
- Amazon Web Services
- Creating the Movable Type Plug-in
- Perl, Amazon, and Movable Type Resources
- Apache Axis2
- REST
- REST Resources
- SOAP
- Informit Articles and Sample Chapters
- Books and e-Books
- Official Documentation
- SOAP and Java
- Informit Articles and Sample Chapters
- Books and e-Books
- Official Documentation
- WSDL
- Informit Articles and Sample Chapters
- Books and e-Books
- Official Documentation
- UDDI
- UDDI Resources
- XML-RPC
- XML-RPC in PHP
- Informit Articles and Sample Chapters
- Books and e-Books
- Official Documentation
- Ajax
- Asynchronous Javascript
- Client-side XSLT
- SAJAX and PHP
- Ajax Resources
- JSON
- Ruby on Rails
- Creating Objects
- Ruby Basics: Arrays and Other Sundry Bits
- Ruby Basics: Iterators and Persistence
- Starting on the Rails
- Rails and Databases
- Rails: Ajax and Partials
- Rails Resources
- Web Services Security
- Web Services Security Resources
- SAML
- Informit Articles and Sample Chapters
- Books and e-Books
- Specification and Implementation
- XML Digital Signatures
- XML Digital Signatures Resources
- XML Key Management Services
- Resources for XML Key Management Services
- Internationalization
- Resources
- Grid Computing
- Grid Resources
- Web Services Resource Framework
- Web Services Resource Framework Resources
- WS-Addressing
- WS-Addressing Resources
- WS-Notifications
- New Languages: XML in Use
- Informit Articles and Sample Chapters
- Books and e-Books
- Official Documentation
- Google Web Toolkit
- GWT Basic Interactivity
- Google Sitemaps
- Google Sitemaps Resources
- Accessibility
- Web Accessibility
- XML Accessibility
- Accessibility Resources
- The Semantic Web
- Defining a New Ontology
- OWL: Web Ontology Language
- Semantic Web Resources
- Google Base
- Microformats
- StructuredBlogging
- Live Clipboard
- WML
- XHTML-MP
- WML Resources
- Google Web Services
- Google Web Services API
- Google Web Services Resources
- The Yahoo! Web Services Interface
- Yahoo! Web Services and PHP
- Yahoo! Web Services Resources
- eBay REST API
- WordML
- WordML Part 2: Lists
- WordML Part 3: Tables
- WordML Resources
- DocBook
- Articles
- Books and e-Books
- Official Documentation and Implementations
- XML Query
- Informit Articles and Sample Chapters
- Books and e-Books
- Official Documentation
- XForms
- Informit Articles and Sample Chapters
- Books and e-Books
- Official Documentation
- Resource Description Framework (RDF)
- Informit Articles and Sample Chapters
- Books and e-Books
- Official Documentation
- Topic Maps
- Informit Articles and Sample Chapters
- Books and e-Books
- Official Documentation, Implementations, and Other Resources
- Rich Site Summary (RSS)
- Informit Articles and Sample Chapters
- Books and e-Books
- Official Documentation
- Simple Sharing Extensions (SSE)
- Atom
- Podcasting
- Podcasting Resources
- Scalable Vector Graphics (SVG)
- Informit Articles and Sample Chapters
- Books and e-Books
- Official Documentation
- OPML
- OPML Resources
- Summary
- Projects
- JavaScript TimeTracker: JSON and PHP
- The Javascript Timetracker
- Refactoring to Javascript Objects
- Creating the Yahoo! Widget
- Web Mashup
- Google Maps
- Indeed Mashup
- Mashup Part 3: Putting It All Together
- Additional Resources
- Frequently Asked Questions About XML
- What's XML, and why should I use it?
- What's a well-formed document?
- What's the difference between XML and HTML?
- What's the difference between HTML and XHTML?
- Can I use XML in a browser?
- Should I use elements or attributes for my document?
- What's a namespace?
- Where can I get an XML parser?
- What's the difference between a well-formed document and a valid document?
- What's a validating parser?
- Should I use DOM or SAX for my application?
- How can I stop a SAX parser before it has parsed the entire document?
- 2005 Predictions
- 2006 Predictions
- Nick's Book Picks
WS-Notifications is a specification -- or rather, a group of specifications -- that enables you to set up a system in which one part of your application can request to be notified when a particular event occurs. The standardization of this process enables you to create a publish-subscribe system, easily adding or removing "topics" for which a component wishes to receive notifications.
For example, we have previously talked about the Web Services Resource Framework (WSRF), which gets around the problem of the stateless nature of Web services by creating WS-Resources, or Web service requests that include information to identify a specific resource. One common use for WS-Notifications is for one resource to subscribe to receive notifications when changes occur in another resource. For example, you might have a service that monitors a database. That service will need to be notified in the event that the databases log files fill up, or if a particular threshold is reached.
In its simplest form, the system involves a notificationProducer, which sends notifications to a notificationConsumer. These notifications get sent in response to specific "situations", but only when the consumer has been subscribe to a particular "topic". For example, I might have a service that subscribes to the topic "diskFull":
When you come down to it, a NotificationConsumer is just a Web service designed to receive specific messages. For example, we might define it with this WSDL file:
<?xml version="1.0" encoding="UTF-8"?> <definitions name="DatabaseAdministrator" targetNamespace="http://example.com/database" xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="http://example.com/database" xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/03/addressing" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:wsntw="http://docs.oasis-open.org/wsn/2004/06/wsn-WS-BaseNotification-1.2-draft-01.wsdl" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"> <wsdl:import namespace="http://docs.oasis-open.org/wsrf/2004/06/wsrf-WS-ResourceProperties-1.2-draft-01.wsdl" location="WS-BaseN.wsdl" /> <types> <xsd:schema targetNamespace="http://example.com/database" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <xsd:import namespace="http://schemas.xmlsoap.org/ws/2004/03/addressing" schemaLocation="WS-Addressing.xsd" /> </xsd:schema> </types> <binding name="ConsumerSoapBinding" type="wsntw:NotificationConsumer"> <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/> <operation name="Notify"> <input> <soap:body use="literal"/> </input> <output> <soap:body use="literal"/> </output> </operation> </binding> <service name="ConsumerService"> <port name="ConsumerPort" binding="tns:ConsumerSoapBinding"> <soap:address location="http://example.com/databaseMessageConsumer"/> </port> </service> </definitions>
When you come right down to it, this is a pretty simple service. It has only one operation, Notify, that gets defined in the imported WS-BaseN.wsdl document, part of the WS-Notification specification.
To subscribe to a topic, the NotificationConsumer sends a message to the NotificationProducer:
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:db="http://example.org/databaseSystem" xmlns:wsa="http://www.w3.org/2005/02/addressing" xmlns:wsnt="http://docs.oasis-open.org/wsn/2004/06/wsn-WS-BaseNotification-1.2-draft-01.xsd"> <SOAP-ENV:Header> <wsa:Action> http://docs.oasis-open.org/wsn/2004/06/WS-BaseNotification/Subscribe </wsa:Action> <wsa:To SOAP-ENV:mustUnderstand="1">http://example.com/database</wsa:To> <db:DatabaseId>CINDB</db:DatabaseId> </SOAP-ENV:Header> <SOAP-ENV:Body> <wsnt:Subscribe> <wsnt:ConsumerReference> <wsa:EndpointReference> <wsa:Address>http://example.com/databaseMessageConsumer</wsa:Address> </wsa:EndpointReference> </wsnt:ConsumerReference> <wsnt:TopicExpression Dialect="http://docs.oasis-open.org/wsn/2004/06/TopicExpression/Simple"> db:diskFull </wsnt:TopicExpression> <wsnt:UseNotify>true</wsnt:UseNotify> <wsnt:InitialTerminationTime> 2007-12-31T12:00:00 </wsnt:InitialTerminationTime> </wsnt:Subscribe> </SOAP-ENV:Body> </SOAP-ENV:Envelope>
The Header includes the fact that we are trying to create a subscription, as well as the resource to which we are attempting to subscribe, the database identified as CINDB. The actual subscription requests to includes the And pointReference for the consumer, which in this case is a simple URL. It also includes the topic or topics to which we want to subscribe (in this case, the diskFull topic), whether we want to use the Notify form (the alternative, raw messages, is much more difficult to specify in a WSDL file) and how long we want the subversion to continue. Note that this is the InitialTerminationTime for the subscription, and can be extended at any time.
The producer sends back a confirmation message:
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:db="http://example.org/databaseSystem" xmlns:wsa="http://www.w3.org/2005/02/addressing" xmlns:wsnt="http://docs.oasis-open.org/wsn/2004/06/wsn-WS-BaseNotification-1.2-draft-01.xsd"> <SOAP-ENV:Header> <wsa:Action> http://docs.oasis-open.org/wsn/2004/06/WS-BaseNotification/SubscribeResponse </wsa:Action> <wsa:To SOAP-ENV:mustUnderstand="1"> http://example.com/databaseMessageConsumer </wsa:To> </SOAP-ENV:Header> <SOAP-ENV:Body> <wsnt:SubscribeResponse> <wsnt:SubscriptionReference> <wsa:Address> http://example.com/databaseSubscriptions </wsa:Address> <wsa:ReferenceProperties> <db:ResourceID>39983872</db:ResourceID> </wsa:ReferenceProperties> </wsnt:SubscriptionReference> </wsnt:SubscribeResponse> </SOAP-ENV:Body> </SOAP-ENV:Envelope>
The response message includes the ResourceID for the subscription itself, so the client can extend or cancel it at any time. So engines can also be paused and resumed.
The actual notification comes in the form of a SOAP message, the body of which might look something like this:
<wsnt:Notify> <wsntw:NotificationMessage> <wsnt:Topic Dialect="http://docs.oasis-open.org/wsn/2004/06/TopicExpression/Simple"> db:diskFull </wsnt:Topic> <wsnt:ProducerReference> <wsa:EndpointReference xmlns:wsa="http://www.w3.org/2005/02/addressing" xmlns:db="http://example.org/databaseSystem"> <wsa:Address>http://example.com/database</wsa:Address> <wsa:ReferenceProperties> <db:ResourceId>RES1228</db:ResourceId> </wsa:ReferenceProperties> </wsa:EndpointReference> </wsnt:ProducerReference> <wsnt:Message> <db:DiskFullMessage> <db:MessageTitle> Disk Full </db:MessageTitle> <db:MessageContent> The Q: drive, on which the database stores its log files, is now at 95% of capacity. Please take action to resolve this issue. </db:MessageContent> </db:DiskFullMessage> </wsnt:Message> </wsntw:NotificationMessage> </wsnt:Notify>
The message starts by specifying the topics for which this message contains notifications. A NotificationProducer may send notifications for more than one topic at a single message, if the consumer allows it. Next, the message specifies the NotificationProducer from which the notification is being sent. The ResourceId referenced in the EndpointReference refers to the actual subscription, making it straightforward for the consumer to cancel (or destroy) its subscription if necessary. (Don't you wish spam messages came with such a capability?) Finally, we have the message itself, which includes the message title and content.
Available topics are defined in a topicSpace, which is a collection of one or more topicTrees. For example:
<wstop:topicSpace name="DatabaseTopics" targetNamespace="http://example.com/database" xmlns:db="http://example.org/database" xmlns:wstop="http://docs.oasis-open.org/wsn/2004/06/wsn-WS-Topics-1.2-draft-01.xsd"> <wstop:topic name="Systems"> <wstop:topic name="ResourceLevels"> <wstop:topic name="diskFull"/> <wstop:topic name="CPULockedUp" /> <wstop:topic name="networkSwamped" /> </wstop:topic> <wstop:topic name="Errors"> <wstop:topic name="unexpectedShutdown" /> <wstop:topic name="diskFull" /> <wstop:topic name="driveCorruption"/> <wstop:topic name="DOSAttack"/> <wstop:topic name="alienAttack"/> </wstop:topic> </wstop:topic> <wstop:topic name="Databases"> <wstop:topic name="Active"> <wstop:topic name="EmployeeDB"/> <wstop:topic name="InventoryDB"/> </wstop:topic> <wstop:topic name="Inactive"> <wstop:topic name="VacationRequestsDB"/> </wstop:topic> </wstop:topic> </wstop:topicSpace>
So in this case, a consumer could actually choose from Systems/ResourceLevels/diskFull and Systems/Errors/diskFull.
The actual NotificationProducer is just a Web service with additional ResourceProperties and operations. (For a refresher on Resource Properties, see the guide entry on WSRF.) For example, the service might have the following Resource Property:
<wsn:NotificationProducerRP xmlns:wsn="http://docs.oasis-open.org/wsn/2004/06/wsn-WS-BaseNotification-1.2-draft-01.xsd"> <wsn:Topic>diskFull</wsn:Topic> <wsn:Topic>systemReset</wsn:Topic> <wsn:FixedTopicSet>false</wsn:FixedTopicSet> <wsn:TopicExpressionDialects> http://docs.oasis-open.org/wsn/2004/06/TopicExpression/Simple </wsn:TopicExpressionDialects> </wsn:NotificationProducerRP>
In this case, the producer is advertising that it sends notifications on the diskFull and systemReset topics, but that a consumer can subscribe to additional topics, and the NotificationProducer will send them notifications applicable. The producer has also specified that it expects subscription topics to come in the "simple" dialect, meaning that all topics are at the root of the topicSpace.
Defining a NotificationProducer itself involves making sure the appropriate operations and elements have been defined:
<?xml version="1.0" encoding="UTF-8"?> <definitions name="Database" targetNamespace="http://example.com/database" xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="http://example.com/database" xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/03/addressing" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:wsrp="http://docs.oasis-open.org/wsrf/2004/06/wsrf-WS-ResourceProperties-1.2-draft-01.xsd" xmlns:wsrpwsdl= "http://docs.oasis-open.org/wsrf/2004/06/wsrf-WS-ResourceProperties-1.2-draft-01.wsdl" xmlns:wsrl="http://docs.oasis-open.org/wsrf/2004/06/wsrf-WS-ResourceLifetime-1.2-draft-01.xsd" xmlns:wsrlwsdl= "http://docs.oasis-open.org/wsrf/2004/06/wsrf-WS-ResourceLifetime-1.2-draft-01.wsdl" xmlns:wssg="http://docs.oasis-open.org/wsrf/2004/06/wsrf-WS-ServiceGroup-1.2-draft-01.xsd" xmlns:wssgwsdl= "http://docs.oasis-open.org/wsrf/2004/06/wsrf-WS-ServiceGroup-1.2-draft-01.wsdl" xmlns:wsnt="http://docs.oasis-open.org/wsn/2004/06/wsn-WS-BaseNotification-1.2-draft-01.xsd" xmlns:wsntw= "http://docs.oasis-open.org/wsn/2004/06/wsn-WS-BaseNotification-1.2-draft-01.wsdl" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"> <wsdl:import namespace="http://docs.oasis-open.org/wsrf/2004/06/wsrf-WS-ResourceProperties-1.2-draft-01.wsdl" location="WS-ResourceProperties.wsdl" /> <wsdl:import namespace="http://docs.oasis-open.org/wsrf/2004/06/wsrf-WS-ResourceLifetime-1.2-draft-01.wsdl" location="WS-ResourceLifetime.wsdl" /> <wsdl:import namespace="http://docs.oasis-open.org/wsrf/2004/06/wsrf-WS-ServiceGroup-1.2-draft-01.wsdl" location="WS-ServiceGroup.wsdl" /> <wsdl:import namespace="http://docs.oasis-open.org/wsn/2004/06/wsn-WS-BaseNotification-1.2-draft-01.wsdl" location="WS-BaseN.wsdl" /> <types> <xsd:schema targetNamespace="http://example.com/database" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <xsd:import namespace="http://schemas.xmlsoap.org/ws/2004/03/addressing" schemaLocation="WS-Addressing.xsd" /> <xsd:import namespace="http://docs.oasis-open.org/wsrf/2004/06/wsrf-WS-ResourceLifetime-1.2-draft-01.xsd" schemaLocation="WS-ResourceLifetime.xsd" /> <xsd:element name="createDatabase"> <xsd:complexType/> </xsd:element> <xsd:element name="createDatabaseResponse"> <xsd:complexType> <xsd:sequence> <xsd:element ref="wsa:EndpointReference"/> </xsd:sequence> </xsd:complexType> </xsd:element> <xsd:element name="GenericDatabaseProperties"> <xsd:complexType> <xsd:sequence> <xsd:element ref="wsrl:CurrentTime" minOccurs="1" maxOccurs="1"/> <xsd:element ref="wsrl:TerminationTime" minOccurs="1" maxOccurs="1"/> <xsd:element ref="wsnt:Topic" minOccurs="1" maxOccurs="unbounded"/> <xsd:element ref="wsnt:FixedTopicSet" minOccurs="1" maxOccurs="1"/> <xsd:element ref="wsnt:TopicExpressionDialects" minOccurs="1" maxOccurs="unbounded"/> <xsd:any/> </xsd:sequence> </xsd:complexType> </xsd:element> </xsd:schema> </types> ... <portType name="DatabasePortType" wsrp:ResourceProperties="tns:GenericDatabaseProperties"> ... <wsdl:operation name="Subscribe"> <wsdl:input message="wsntw:SubscribeRequest" wsa:Action="http://docs.oasis-open.org/wsn/2004/06/wsn-WS-BaseNotification/Subscribe"/> <wsdl:output message="wsntw:SubscribeResponse" wsa:Action="http://docs.oasis-open.org/wsn/2004/06/wsn-WS-BaseNotification/SubscribeResponse"/> <wsdl:fault name="ResourceUnknownFault" message="wsntw:ResourceUnknownFault" /> <wsdl:fault name="SubscribeCreationFailedFault" message="wsntw:SubscribeCreationFailedFault"/> <wsdl:fault name="TopicPathDialectUnknownFault" message="wsntw:TopicPathDialectUnknownFault"/> </wsdl:operation> <wsdl:operation name="GetCurrentMessage"> <wsdl:input message="wsntw:GetCurrentMessageRequest" wsa:Action="http://docs.oasis-open.org/wsn/2004/06/wsn-WS-BaseNotification/GetCurrentMessage"/> <wsdl:output message="wsntw:GetCurrentMessageResponse" wsa:Action="http://docs.oasis-open.org/wsn/2004/06/wsn-WS-BaseNotification/GetCurrentMessageResponse"/> <wsdl:fault name="ResourceUnknownFault" message="wsntw:ResourceUnknownFault" /> <wsdl:fault name="InvalidTopicExpressionFault" message="wsntw:InvalidTopicExpressionFault" /> <wsdl:fault name="TopicNotSupportedFault" message="wsntw:TopicNotSupportedFault" /> <wsdl:fault name="NoCurrentMessageOnTopicFault" message="wsntw:NoCurrentMessageOnTopicFault" /> </wsdl:operation> </portType> <binding name="DatabaseSoapBinding" type="tns:DatabasePortType"> <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/> ... <operation name="renewDatabase"> <input> <soap:body use="literal"/> </input> <output> <soap:body use="literal"/> </output> </operation> <operation name="Subscribe"> <input> <soap:body use="literal"/> </input> <output> <soap:body use="literal"/> </output> </operation> <operation name="GetCurrentMessage"> <input> <soap:body use="literal"/> </input> <output> <soap:body use="literal"/> </output> </operation> </binding> ...
By adding these two operations, the guts of which are defined in the imported specifications, you can turn any Web service into a NotificationProducer.