WebReference.com - Part 2 of Chapter 3: Professional XML Web Services, from Wrox Press Ltd (3/5) | WebReference

WebReference.com - Part 2 of Chapter 3: Professional XML Web Services, from Wrox Press Ltd (3/5)

To page 1To page 2current pageTo page 4To page 5
[previous] [next]

Professional XML Web Services


SOAP encoding allows us to define enumerated types. It borrows once again from XML Schemas, which also has the concept of an enumeration. An enumeration is a named set of values, based on a basic type. For example, we could define an enumeration that represented geographical locations ("North, "South", etc). To define an enumeration, we must use XML Schemas.

Here is an example of an enumeration that defines a set of geographical regions.

<simpleType name="Region" base="xsd:string">
   <enumeration value="North"/>
   <enumeration value="South"/>
   <enumeration value="East"/>
   <enumeration value="West"/>

If this enumeration appeared in a referenced schema, we could then use this type in a SOAP message just as we would any other type.

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
      <m:GetSalesTotals xmlns:m="http://www.wrox.com/sales/">
         <m:reg xsi:type="m:Region">East</m:reg>

Binary Data

As part of the simple types it supports, SOAP and XML Schemas provide a type for representing binary data. One approach for working with binary data is to use the base64 type. We can represent binary data, such as an image file, as an array of bytes in the message. The base64 type converts binary data to text using the base64-encoding algorithm of XML Schemas. There is no relationship between SOAP and base64-encoding; if we use it, our application (or implementation of SOAP for your platform) must be able to understand and work with base64-encoding.

Catch All

In addition to the simple types, many languages have a "universal" data type or placeholder, something that can represent a variety of types within that language. In COM, the variant serves this purpose, as does the any type in CORBA. SOAP accounts for this possibility with the polymorphic accessor. If we are serializing a value in the form of a polymorphic accessor, we must provide the type attribute.

The polymorphic accessor is more difficult to pronounce than to use! Let's assume we are passing in a value representing a person's age, and that type could vary depending on how the information was to be used. If the value of our data is a float, it would appear like this:

<age xsi:type="xsd:float">3.5</age>

If is a string, it would appear like this:

<age xsi:type="xsd:string">3 and a half years old</age>

Both examples are legal if the age element has been defined as being a polymorphic accessor, meaning that its data type will vary.

What About XML?

Those frequenting the SOAP discussion lists and newsgroups will notice the recurring question: "How do I send XML in a SOAP payload?" or something to that effect. This is a general problem related to XML, but there are a couple of approaches we can use to transmit XML inside SOAP. We can:

To page 1To page 2current pageTo page 4To page 5
[previous] [next]

Created: November 19, 2001
Revised: November 19, 2001

URL: http://webreference.com/authoring/languages/xml/webservices/chap3/2/3.html