Types
WSDL makes use of XSD, XML Schema Definition, for its type system. Some of the more common types, a few of which you have seen used as the types in message elements, are shown in Table 3.1.
Table 3.1 Common Methods of the Session Object
Type |
Visual Basic Equivalent |
anyURI |
String |
base64Binary |
Byte |
boolean |
Boolean |
byte |
Integer |
date |
Date |
dateTime |
Date |
double |
Double |
duration |
String |
ENTITIES |
String |
ENTITY |
String |
float |
Single |
ID |
String |
IDREF |
String |
IDREFS |
String |
int |
Long |
language |
String |
Name |
String |
NCName |
String |
NMTOKEN |
String |
NMTOKENS |
String |
normalizedString |
String |
NOTATION |
String |
QName |
String |
short |
Integer |
string |
String |
time |
Date |
token |
String |
unsignedByte |
Byte |
unsignedShort |
Long |
WSDL's type system allows for more complex data types, such as arrays, enumerations, and even objects to be defined by combining the simple types shown in Table 3.1. The following example shows a new type, called NewType, which contains an integer named Var1 and a byte named Var2.
<s:element name="NewType"> <s:complextype> <s:sequence> <s:element minOccurs="1", maxOccurs="1" name="Var1" type="s:int"> <s:element minOccurs="1", maxOccurs="1" name="Var2" type="s:byte"> </s:sequence> </s:complextype> </s:element>
Now, apply this to the StringReturn method that you have been looking at throughout this hour. The message for the StringReturn method defined a message part containing an element named StringReturn. StringReturn is defined in Listing 3.8 as being an empty element (line 6). This would suggest that the method StringReturn accepts no input parameters. The return of the method, on the other hand, does return data. Lines 8 through 15 define a type, StringReturnResponse, which contains one, and only one, string type variable.
Listing 3.8 Typing in WSDL
1: <types> 2: <s:schema attributeFormDefault="qualified" 3: elementFormDefault="qualified" 4: targetNamespace="http:\http://www.myServer.com\DataTypes"> 5: <s:element name="StringReturn"> 6: <s:complexType /> 7: </s:element> 8: <s:element name="StringReturnResponse"> 9: <s:complexType> 10: <s:sequence> 11: <s:element minOccurs="1" maxOccurs="1" 12: name="StringReturnResult" 13: nillable="true" type="s:string" /> 13: </s:sequence> 14: </s:complexType> 15: </s:element> 16: <s:element name="string" nillable="true" type="s:string" /> 17: </s:schema> 18: </types>
If you needed to return an even more complicated type, such as the enumeration shown in Listing 3.9, you would define the enumeration, lines 9 through 15, as a simple type. Yes, a simple type because it will not be made up of other types but will in fact be the building block of more complex types. This enumeration can then be used to create more complex types, such as the EnumReturnResponse shown in line 1.
Listing 3.9 Describing an Enumeration with XSD
1: <s:element name="EnumReturnResponse"> 2: <s:complexType> 3: <s:sequence> 4: <s:element minOccurs="1" maxOccurs="1" 5: name="EnumReturnResult" type="s0:Color" /> 6: </s:sequence> 7: </s:complexType> 8: </s:element> 9: <s:simpleType name="Color"> 10: <s:restriction base="s:string"> 11: <s:enumeration value="Red" /> 12: <s:enumeration value="Blue" /> 13: <s:enumeration value="Green" /> 14: </s:restriction> 15: </s:simpleType> 16: </s:element>