WSDL 2.0 - types
Jakob Jenkov |
The WSDL types
element describes the data types used by your web service. Most often a web service
will have an input type, an output type, and perhaps a fault type. If the web service has more than one operation,
then each operation may have its own input type, output type and fault type.
The data types can be declared in any language you like, as long as your web service API supports it. Data types are often specified using XML Schema though, since XML Schema is a natural fit for XML structures.
Here is an example types
element that uses XML Schema to define an input type, an output type,
and a fault type:
<?xml version="1.0" encoding="utf-8" ?> <description xmlns="http://www.w3.org/ns/wsdl" targetNamespace= "http://jenkov.com/MyService" xmlns:tns= "http://jenkov.com/MyService" xmlns:stns= "http://jenkov.com/MyService/schema" . . . > ... <types> <xs:schema xmlns:xs= "http://www.w3.org/2001/XMLSchema" targetNamespace= "http://jenkov.com/MyService/schema" xmlns:tns= "http://jenkov.com/MyService/schema" > <xs:element name="latestTutorialRequest" type="typeLatestTutorialRequest"/> <xs:complexType name="typeLatestTutorialRequest"> <xs:sequence> <xs:element name="date" type="xs:date"/> </xs:sequence> </xs:complexType> <xs:element name="latestTutorialResponse" type="xs:string"/> <xs:element name="invalidDateError" type="xs:string"/> </xs:schema> </types> . . . </description>
The latestTutorialRequest
element is the input type. As you can see,
this element is of type typeLatestTutorialRequest
, and it can contain
a date, telling which date to get the latest tutorial after.
The latestTutorialResponse
element is the output type. The content of
this element is just a string. This will contain the URL for the latest tutorial published
after the given date, or an empty string if no tutorial was published after the given date.
The invalidDateError
element is the fault type. The content of this element is just
a string. This string can contain a textual explanation of why the date given in the input request
was faulty.
XML Schema: Top Level Elements Only
In XML Schema you can define all kinds of elements and types. However, only elements declared
as single elements (there can be only one), and as top level elements (not nested inside other elements),
can be referred to by the WSDL 2.0 interface
and operation
elements. In other words,
you could not use the date
element by itself as an input or output type of an operation,
since it is declared inside the latestTutorialRequest
.
The Schema Name Space
Notice how the example shown earlier declared a name space with the prefix stns
.
The Schema Target Name Space (stns). This name space URI is also referenced as the target
name space of the XML Schema, but here it is declared via targetNameSpace
and
tns
, not stns
.
The prefixes are not important though. The prefixes
used inside XML Schema only exist within the Schema declaration, not outside. Therefore these
targetNamespace
and tns
namespaces do not conflict with those defined
in the description
element.
Tweet | |
Jakob Jenkov |