Databases Reference
In-Depth Information
Loosely-typed services
With a loosely-typed approach, we use XML Schema to define the overall structure
of the XML instance, that is, which elements may appear in the document, whether
they are optional or mandatory, and how often they may occur. But define minimal
constraints around the content of each element. Using this approach, our definition
of a credit card could be as shown in the following code snippet:
<xsd:complexTypename="CreditCard">
<xsd:sequence>
<xsd:elementname="cardType"type="xsd:string"/>
<xsd:elementname="cardHolderName"type="xsd:string"/>
<xsd:elementname="cardNumber"type="xsd:integer"/>
<xsd:elementname="expiryMonth"type="xsd:integer"/>
<xsd:elementname="expiryYear"type="xsd:integer"/>
<xsd:elementname="securityNo"type="xsd:integer"/>
</xsd:sequence>
</xsd:complexType>
This is about as loose a definition as we could provide, though we could have gone
one step further and made every element a string.
The major advantage of this approach is that the service is far more conducive
to change; following on from our previous example, if oBay decided to accept
American Express as payment, then no changes would be required to the schema or
service contract.
However, the key disadvantage with this approach is that we have far less control
over the data that comes into our service and thus need to rely on the required
validation being implemented elsewhere within our service.
What we want to avoid is coding the majority of this validation into the service itself,
as this can overcomplicate the implementation of the service, result in the same
validation being implemented in multiple services (possibly inconsistently), as well
as make change harder to manage, as we would have to update the service code
every time the validation rules changed.
Another disadvantage with this approach is that the service contract provides far
less guidance to the consumer of the service as to what constitutes valid data, thus
additional documentation would be required along with the service to define this.
 
Search WWH ::




Custom Search