Search This Blog

Friday, February 16, 2007

Service contracts

XML is a common format for message exchange in Service Oriented Architectures. One of the most important things is to formalize the messages exchanged between systems. This can be done using XML schema definitions. XML schema defines the rules to which a XML message must conform when it is constructed. A well defined schema brings the following advantages:
  1. Validate messages when they are constructed and thus before they are sent.
  2. Generate Java classes from the XML schema for use in XML binding frameworks.
  3. Easily construct mock XML messages with a tool like XMLSpy for use in (unit)tests or mock implementations of services.

With “well defined schema” I mean a schema definition which is constructed before the actual service is implemented so every element in the schema is well thought out. Another example: when some element’s value is an enumeration of some values, define this in the schema definition and not in a separate document (I,ve seen it happen). This way you restrict the values an element can contain and it becomes much easier to construct mock XML messages for testing purposes.

The bottom line is: invest in the construction of well thought out service contracts.

A good reference for designing XML schema definitions can be found here.

No comments: