One issue that hit people when they write message orientated systems is how to
control what messages are allowed to be sent and also how to validate those
messages. This blog entry looks at how SSB handles these issues.
SSB enforces that all messages sent must be of a predefined type - called a Message
type. Message Types have a validation associated with them that can be
one of three values
-
Empty - the message is simply an notification that carries no associated data
-
Varbinary - the data associated with the message will not be validated by SSB
-
XML - the data associated with the message will be validated as wellformed XML.
Number 3. can be taken even further. Once you specify that a message must be
wellformed XML, you can also, optionally, associate an XML Schema against which
the message will be validated (XML Schema can now be loaded as a first class
database object).
The Syntax for creating a Message Type is as follows (be warned that this is the
syntax for the build of Yukon I currently have - the Beta 1 syntax will,
apparently, be different).
CREATE MESSAGE TYPE
[http://develop.com/richardb/shippingRequest]
ENCODING VARBINARY
or for a validated XML message
CREATE MESSAGE TYPE
[http://develop.com/richardb/validatedShippingRequest]
ENCODING XML WITH 'http://develop.com/richardb/shippingSchema'
The URL after the the CREATE MESSAGE TYPE is simply a unique identifier for the
message. Using indentifiers of this form make keeping uniqueness across complex
distributed systems simpler.
So this determines the validation of messages, however, how do we restrict what
messages may be sent to a particular service? This is the role of a Contract.
A Contract determines which message types may be sent and received within a
particular dialog - determining which messages can be sent by the dialog
initiator and which can be sent by the dialog target (and message can also be
specified as being allowed by either). These rules are then enforced by SSB.
Here is an example contract:
CREATE CONRACT
[http://develop.com/richardb/shippingContract]
(
[http://develop.com/richardb/validatedShippingRequest]
SENT BY INITIATOR
[http://develop.com/richardb/validatedShippingResponse]
SENT BY TARGET
)
This contract is then bound to a service by the service definition.