XML Schema Data Typing - Page 8
April 10, 2002
In order for a SOAP client to communicate effectively with a
SOAP server, the client and server must agree on a data type system. By
default, XML 1.0 does not provide a data type system. In contrast, every
programming language provides some basic facility for declaring data types,
such as integers, floats, doubles, and strings. One of the greatest challenges
in building web services is therefore creating a common data type system that
can be used by a diverse set of programming languages running on a diverse set
of operating systems.
WSDL does not aim to create a standard for XML data typing. In
fact, WSDL is specifically designed for maximum flexibility and is therefore
not tied exclusively to any one data type system. Nonetheless, WSDL does
default to the W3C XML Schema specification. The XML Schema specification is
also currently the most widely used specification for data typing.
The more you know about XML Schemas, the better you can
understand complex WSDL files. A full discussion of XML Schemas is beyond the
scope of this chapter. However, two facts are crucially important.
First, the XML Schema specification includes a basic type system
for encoding most data types. This type system includes a long list of
built-in simple types, including strings, floats, doubles, integers, time, and
date. This list, shown in Table
6-1, is excerpted from the XML Schema Part 0: Primer (http://www.w3org/TR/2000/WD=xmlschema=0=20000407/).
If your application sticks to these simple data types, there is no need to
include the WSDL types element, and the resulting
WSDL file is extremely simple. For example, our first two WSDL files use only
strings and floats.
Table 6-1: A list of the main XML Schema built-in simple types
|
Simple type |
Example(s) |
|
string |
Web Services |
|
Boolean |
true, false, 1, 0 |
|
float |
-INF, -1E4, -0, 0, 12.78E-2, 12, INF, NaN |
|
double |
-INF, -1E4, -0, 0, 12.78E-2, 12, INF, NaN |
|
decimal |
-1.23, 0, 123.4, 1000.00 |
|
binary |
100010 |
|
integer |
-126789, -1, 0, 1, 126789 |
|
nonPositiveInteger |
-126789, -1, 0 |
|
negativeInteger |
-126789, -1 |
|
long |
-1, 12678967543233 |
|
int |
-1, 126789675 |
|
short |
-1, 12678 |
|
byte |
-1, 126 |
|
nonNegativeInteger |
0, 1, 126789 |
|
unsignedLong |
0, 12678967543233 |
|
unsignedInt |
0, 1267896754 |
|
unsignedShort |
0, 12678 |
|
unsignedByte |
0, 126 |
|
positiveInteger |
1, 126789 |
|
date |
1999-05-31 |
|
time |
13:20:00.000, 13:20:00.000-05:00
|
Second, the XML Schema specification provides a facility for
creating new data types. This is important if you want
to create data types that go beyond what is already defined within the Schema.
For example, a service might return an array of floats or a more complex stock
quote object containing the high, low, and volume figures for a specific
stock. Whenever your service goes beyond the simple XML Schema data types, you
must declare these new data types within the WSDL types element.
In the next two sections of this chapter, we present two
specific examples of using XML Schemas to create new data types. The first
focuses on arrays; the second focuses on a more complex data type for
encapsulating product information.
Automatically Generating WSDL Files - Page 7
Web Services Essentials
XML Schema Data Typing (cont.) - Page 9
|