Web Developer's Virtual Library: Encyclopedia of Web Design Tutorials, Articles and Discussions


WDVL Newsletter

Active Server Pages
JSP/Java Servlets
Microsoft SQL Server
Daily Backup
Dedicated Servers
Streaming Audio/Video
24-hour Support    

jobs.webdeveloper.com

Hiermenus


e-commerce
Partner With Us















Developer Channel
FlashKit.com
JavaScript.com
JavaScriptSource
Developer Jobs
ScriptSearch
StreamingMediaWorld
Web Developer's Journal
Web Developer's Virtual Library
WebDeveloper.com
Webreference
Web Hosts
XMLfiles.com

internet.com
IT
Developer
Internet News
Small Business
Personal Technology

Search internet.com
Advertise
Corporate Info
Newsletters
Tech Jobs
E-mail Offers


XML Schema Data Typing (cont.) - Page 11

April 10, 2002

Complex Types

Our final topic is the use of complex data types. For example, consider a home monitoring service that provides a concise update on your home. The data returned could include multiple data elements, such as the current temperature, security status, and whether the garage door is open or closed. Encoding this data into WSDL requires additional knowledge of XML Schemas, which reinforces the main precept that the more you know about XML Schemas, the better you will understand complex WSDL files.

To explore complex types, consider the WSDL file in Example 6-10. This WSDL file describes our Product Service from Chapter 5. The complex types are indicated in bold.

Example 6-10: ProductService.wsdl

<?xml version="1.0" encoding="UTF-8"?>
<definitions name="ProductService"
  targetNamespace="http://www.ecerami.com/wsdl/ProductService.wsdl"
  xmlns="http://schemas.xmlsoap.org/wsdl/"
  xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
  xmlns:tns="http://www.ecerami.com/wsdl/ProductService.wsdl"
  xmlns:xsd="http://www.w3.org/2001/XMLSchema"
  xmlns:xsd1="http://www.ecerami.com/schema">
 
   <types>
     <xsd:schema
         targetNamespace="http://www.ecerami.com/schema"
         xmlns="http://www.w3.org/2001/XMLSchema">
         <xsd:complexType name="product">
            <xsd:sequence>
               <xsd:element name="name" type="xsd:string"/>
               <xsd:element name="description" type="xsd:string"/>
               <xsd:element name="price" type="xsd:double"/>
               <xsd:element name="SKU" type="xsd:string"/>
            </xsd:sequence>
         </xsd:complexType>
      </xsd:schema>
   </types>
 
   <message name="getProductRequest">
     <part name="sku" type="xsd:string"/>
   </message>
   
   <message name="getProductResponse">
     <part name="product" type="xsd1:product"/>
   </message>
 
   <portType name="Product_PortType">
     <operation name="getProduct">
       <input message="tns:getProductRequest"/>
       <output message="tns:getProductResponse"/>
     </operation>
   </portType>
 
   <binding name="Product_Binding" type="tns:Product_PortType">
     <soap:binding style="rpc"
         transport="http://schemas.xmlsoap.org/soap/http"/>
     <operation name="getProduct">
       <soap:operation soapAction="urn:examples:productservice"/>
       <input>
         <soap:body
             encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
             namespace="urn:examples:productservice"
             use="encoded"/>
       </input>
       <output>
         <soap:body
             encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
             namespace="urn:examples:productservice" use="encoded"/>
       </output>
     </operation>
   </binding>
 
   <service name="Product_Service">
     <port name="Product_Port" binding="tns:Product_Binding">
       <soap:address location=
	   		"http://localhost:8080/soap/servlet/rpcrouter"/>
     </port>
   </service>
</definitions>

Note:Color coded lines have been split for display purposes

The service in Example 6-10 describes a getProduct operation that returns a complex product type for encapsulating product information, including product name, description, price, and SKU number.

The new product type is defined in much the same manner as the array definition from the previous example. The main difference is that we are now using the sequence element. The sequence element specifies a list of subelements and requires that these elements appear in the order specified. XML Schemas also enable you to specify cardinality via the minOccurs and maxOccurs attributes. If these attributes are absent (as in our example), they default to 1, requiring that each subelement must occur exactly one time.

Each subelement can also have its own data type, and you can see that we have mixed and matched string data types with double data types in our example.

XML Schema Data Typing (cont.) - Page 10
Web Services Essentials
XML Schema Data Typing (cont.) - Page 12


Up to => Home / Authoring / Languages / XML / WebServices / WSDL / Essentials




Jupiter Online Media: internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and Jupiter Online Media

Jupitermedia Corporate Info


Legal Notices, Licensing, & Permissions, Privacy Policy.

Web Hosting | Newsletters | Tech Jobs | Shopping | E-mail Offers