- XML Reference Guide
- Overview
- What Is XML?
- Informit Articles and Sample Chapters
- Books and e-Books
- Official Documentation
- Table of Contents
- The Document Object Model
- Informit Articles and Sample Chapters
- Books and e-Books
- Official Documentation
- DOM and Java
- Informit Articles and Sample Chapters
- Books and e-Books
- Implementations
- DOM and JavaScript
- Using a Repeater
- Repeaters and XML
- Repeater Resources
- DOM and .NET
- Informit Articles and Sample Chapters
- Books and e-Books
- Documentation and Downloads
- DOM and C++
- DOM and C++ Resources
- DOM and Perl
- DOM and Perl Resources
- DOM and PHP
- DOM and PHP Resources
- DOM Level 3
- DOM Level 3 Core
- DOM Level 3 Load and Save
- DOM Level 3 XPath
- DOM Level 3 Validation
- Informit Articles and Sample Chapters
- Books and e-Books
- Documentation and Implementations
- The Simple API for XML (SAX)
- Informit Articles and Sample Chapters
- Books and e-Books
- Official Documentation
- SAX and Java
- Informit Articles and Sample Chapters
- Books and e-Books
- SAX and .NET
- Informit Articles and Sample Chapters
- SAX and Perl
- SAX and Perl Resources
- SAX and PHP
- SAX and PHP Resources
- Validation
- Informit Articles and Sample Chapters
- Books and e-Books
- Official Documentation
- Document Type Definitions (DTDs)
- Informit Articles and Sample Chapters
- Books and e-Books
- Official Documentation
- XML Schemas
- Informit Articles and Sample Chapters
- Books and e-Books
- Official Documentation
- RELAX NG
- Informit Articles and Sample Chapters
- Books and e-Books
- Official Documentation
- Schematron
- Official Documentation and Implementations
- Validation in Applications
- Informit Articles and Sample Chapters
- Books and e-Books
- XSL Transformations (XSLT)
- Informit Articles and Sample Chapters
- Books and e-Books
- Official Documentation
- XSLT in Java
- Java in XSLT Resources
- XSLT and RSS in .NET
- XSLT and RSS in .NET Resources
- XSL-FO
- Informit Articles and Sample Chapters
- Books and e-Books
- Official Documentation
- XPath
- Informit Articles and Sample Chapters
- Books and e-Books
- Official Documentation
- XML Base
- Informit Articles and Sample Chapters
- Official Documentation
- XHTML
- Informit Articles and Sample Chapters
- Books and e-Books
- Official Documentation
- XHTML 2.0
- Documentation
- Cascading Style Sheets
- Informit Articles and Sample Chapters
- Books and e-Books
- Official Documentation
- XUL
- XUL References
- XML Events
- XML Events Resources
- XML Data Binding
- Informit Articles and Sample Chapters
- Books and e-Books
- Specifications
- Implementations
- XML and Databases
- Informit Articles and Sample Chapters
- Books and e-Books
- Online Resources
- Official Documentation
- SQL Server and FOR XML
- Informit Articles and Sample Chapters
- Books and e-Books
- Documentation and Implementations
- Service Oriented Architecture
- Web Services
- Informit Articles and Sample Chapters
- Books and e-Books
- Official Documentation
- Creating a Perl Web Service Client
- SOAP::Lite
- Amazon Web Services
- Creating the Movable Type Plug-in
- Perl, Amazon, and Movable Type Resources
- Apache Axis2
- REST
- REST Resources
- SOAP
- Informit Articles and Sample Chapters
- Books and e-Books
- Official Documentation
- SOAP and Java
- Informit Articles and Sample Chapters
- Books and e-Books
- Official Documentation
- WSDL
- Informit Articles and Sample Chapters
- Books and e-Books
- Official Documentation
- UDDI
- UDDI Resources
- XML-RPC
- XML-RPC in PHP
- Informit Articles and Sample Chapters
- Books and e-Books
- Official Documentation
- Ajax
- Asynchronous Javascript
- Client-side XSLT
- SAJAX and PHP
- Ajax Resources
- JSON
- Ruby on Rails
- Creating Objects
- Ruby Basics: Arrays and Other Sundry Bits
- Ruby Basics: Iterators and Persistence
- Starting on the Rails
- Rails and Databases
- Rails: Ajax and Partials
- Rails Resources
- Web Services Security
- Web Services Security Resources
- SAML
- Informit Articles and Sample Chapters
- Books and e-Books
- Specification and Implementation
- XML Digital Signatures
- XML Digital Signatures Resources
- XML Key Management Services
- Resources for XML Key Management Services
- Internationalization
- Resources
- Grid Computing
- Grid Resources
- Web Services Resource Framework
- Web Services Resource Framework Resources
- WS-Addressing
- WS-Addressing Resources
- WS-Notifications
- New Languages: XML in Use
- Informit Articles and Sample Chapters
- Books and e-Books
- Official Documentation
- Google Web Toolkit
- GWT Basic Interactivity
- Google Sitemaps
- Google Sitemaps Resources
- Accessibility
- Web Accessibility
- XML Accessibility
- Accessibility Resources
- The Semantic Web
- Defining a New Ontology
- OWL: Web Ontology Language
- Semantic Web Resources
- Google Base
- Microformats
- StructuredBlogging
- Live Clipboard
- WML
- XHTML-MP
- WML Resources
- Google Web Services
- Google Web Services API
- Google Web Services Resources
- The Yahoo! Web Services Interface
- Yahoo! Web Services and PHP
- Yahoo! Web Services Resources
- eBay REST API
- WordML
- WordML Part 2: Lists
- WordML Part 3: Tables
- WordML Resources
- DocBook
- Articles
- Books and e-Books
- Official Documentation and Implementations
- XML Query
- Informit Articles and Sample Chapters
- Books and e-Books
- Official Documentation
- XForms
- Informit Articles and Sample Chapters
- Books and e-Books
- Official Documentation
- Resource Description Framework (RDF)
- Informit Articles and Sample Chapters
- Books and e-Books
- Official Documentation
- Topic Maps
- Informit Articles and Sample Chapters
- Books and e-Books
- Official Documentation, Implementations, and Other Resources
- Rich Site Summary (RSS)
- Informit Articles and Sample Chapters
- Books and e-Books
- Official Documentation
- Simple Sharing Extensions (SSE)
- Atom
- Podcasting
- Podcasting Resources
- Scalable Vector Graphics (SVG)
- Informit Articles and Sample Chapters
- Books and e-Books
- Official Documentation
- OPML
- OPML Resources
- Summary
- Projects
- JavaScript TimeTracker: JSON and PHP
- The Javascript Timetracker
- Refactoring to Javascript Objects
- Creating the Yahoo! Widget
- Web Mashup
- Google Maps
- Indeed Mashup
- Mashup Part 3: Putting It All Together
- Additional Resources
- Frequently Asked Questions About XML
- What's XML, and why should I use it?
- What's a well-formed document?
- What's the difference between XML and HTML?
- What's the difference between HTML and XHTML?
- Can I use XML in a browser?
- Should I use elements or attributes for my document?
- What's a namespace?
- Where can I get an XML parser?
- What's the difference between a well-formed document and a valid document?
- What's a validating parser?
- Should I use DOM or SAX for my application?
- How can I stop a SAX parser before it has parsed the entire document?
- 2005 Predictions
- 2006 Predictions
- Nick's Book Picks
Web services weren't created solely to enable other companies to access your functionality, but that's certainly a big part of it. Trouble is, in order for others to access your service, they would have to know what the messages the service is looking for, what messages it would return, and where the messages should go. Web Services Description Language (WSDL) provides a way to tell them.
WSDL 1.1 is the current specification, hosted by the World Wide Web Consortium. (Version 1.2 is currently at the Working Draft stage.) It uses XML to define the structure of both incoming and outgoing messages. Consider, for example a service to take orders for our candy company. It might be run by a simple Java class that creates orders and add items to them:
public class CandyOrder { public int createOrder(String custid){ ... } public boolean addItemToOrder(int orderid, String itemid, int quantity){ ... } public String completeOrder(int orderid){ ... } }
The createOrder() method creates an order on the system and returns an order number. The addItemToOrder() takes the product id, quantity, and order information and addes the item to the order. It returns a boolean value that indicates whether the item was successfully added. Finally, the completeOrder() method sends the order off to the fulfillment house and returns a message telling the custmer the approximate delivery date.
A WSDL file starts with a basic definition pointing to the service itself, with progressive layers of information that get more and more specific. For example, we can start with a basic file:
<?xml version="1.0" encoding="UTF-8"?> <definitions name="CandyOrder-binding" targetNamespace="http://www.candyorder.com/definitions/CandyOrderRemoteInterface" xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://www.candyorder.com/definitions/CandyOrderRemoteInterface"> <service name="CandyOrderService"> <port binding="tns:CandyOrderBinding" name="CandyOrderPort"> <soap:address location="http://localhost:8080/sampleweb/servlet/rpcrouter"/> </port> </service> </definitions>
In this case, we're defining a single service by the name of CandyOrderService. To access that service using SOAP, we have to send a message to http://localhost:8080/sampleweb/servlet/rpcrouter. The message will depend on the information in the binding, CandyOrderBinding:
<?xml version="1.0" encoding="UTF-8"?> <definitions name="CandyOrder-binding" targetNamespace="http://www.candyorder.com/definitions/CandyOrderRemoteInterface" xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://www.candyorder.com/definitions/CandyOrderRemoteInterface" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <binding name="CandyOrderBinding" type="tns:CandyOrder"> <soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/> <operation name="completeOrder"> <soap:operation soapAction="" style="rpc"/> <input name="completeOrderRequest"> <soap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://tempuri.org/CandyOrder" use="encoded"/> </input> <output name="completeOrderResponse"> <soap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://tempuri.org/CandyOrder" use="encoded"/> </output> </operation> <operation name="createOrder"> <soap:operation soapAction="" style="rpc"/> <input name="createOrderRequest"> <soap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://tempuri.org/CandyOrder" use="encoded"/> </input> <output name="createOrderResponse"> <soap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://tempuri.org/CandyOrder" use="encoded"/> </output> </operation> <operation name="addItemToOrder"> <soap:operation soapAction="" style="rpc"/> <input name="addItemToOrderRequest"> <soap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://tempuri.org/CandyOrder" use="encoded"/> </input> <output name="addItemToOrderResponse"> <soap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://tempuri.org/CandyOrder" use="encoded"/> </output> </operation> </binding> <service name="CandyOrderService"> <port binding="tns:CandyOrderBinding" name="CandyOrderPort"> <soap:address location="http://localhost:8080/sampleweb/servlet/rpcrouter"/> </port> </service> </definitions>
This binding defines three different operations, each of which corresponds to one of the methods in the original web serivce. For each operation, we can define an optional soapAction and a style. The most commonly-used style is rpc, but some services use the more conversational document style. Each operation defines a n input message and an output message, but doesn't indicate their contents. This section is used more to indicate the flow of messages than their contents. For example, some services might not return a response at all.
To determine the contetn of the differetn messages, you need to know what type of message system you're using. In this case, we're looking for the candyOrder portType:
<?xml version="1.0" encoding="UTF-8"?> <definitions name="CandyOrder-binding" targetNamespace="http://www.candyorder.com/definitions/CandyOrderRemoteInterface" xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://www.candyorder.com/definitions/CandyOrderRemoteInterface" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <portType name="CandyOrder"> <operation name="completeOrder" parameterOrder="orderid"> <input message="tns:completeOrderRequest" name="completeOrderRequest"/> <output message="tns:completeOrderResponse" name="completeOrderResponse"/> </operation> <operation name="createOrder" parameterOrder="custid"> <input message="tns:createOrderRequest" name="createOrderRequest"/> <output message="tns:createOrderResponse" name="createOrderResponse"/> </operation> <operation name="addItemToOrder" parameterOrder="orderid itemid quantity"> <input message="tns:addItemToOrderRequest" name="addItemToOrderRequest"/> <output message="tns:addItemToOrderResponse" name="addItemToOrderResponse"/> </operation> </portType> <binding name="CandyOrderBinding" type="tns:CandyOrder"> <soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/> <operation name="completeOrder"> <soap:operation soapAction="" style="rpc"/> <input name="completeOrderRequest"> <soap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://tempuri.org/CandyOrder" use="encoded"/> </input> <output name="completeOrderResponse"> <soap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://tempuri.org/CandyOrder" use="encoded"/> </output> </operation> ... </binding> <service name="CandyOrderService"> <port binding="tns:CandyOrderBinding" name="CandyOrderPort"> <soap:address location="http://localhost:8080/sampleweb/servlet/rpcrouter"/> </port> </service> </definitions>
This portType defines all three operations, but in this case points to message definitions:
<?xml version="1.0" encoding="UTF-8"?> <definitions name="CandyOrder-binding" targetNamespace="http://www.candyorder.com/definitions/CandyOrderRemoteInterface" xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://www.candyorder.com/definitions/CandyOrderRemoteInterface" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <message name="completeOrderRequest"> <part name="orderid" type="xsd:int"/> </message> <message name="completeOrderResponse"> <part name="result" type="xsd:string"/> </message> <message name="createOrderRequest"> <part name="custid" type="xsd:string"/> </message> <message name="createOrderResponse"> <part name="result" type="xsd:int"/> </message> <message name="addItemToOrderRequest"> <part name="orderid" type="xsd:int"/> <part name="itemid" type="xsd:string"/> <part name="quantity" type="xsd:int"/> </message> <message name="addItemToOrderResponse"> <part name="result" type="xsd:boolean"/> </message> <portType name="CandyOrder"> <operation name="completeOrder" parameterOrder="orderid"> <input message="tns:completeOrderRequest" name="completeOrderRequest"/> <output message="tns:completeOrderResponse" name="completeOrderResponse"/> </operation> <operation name="createOrder" parameterOrder="custid"> <input message="tns:createOrderRequest" name="createOrderRequest"/> <output message="tns:createOrderResponse" name="createOrderResponse"/> </operation> <operation name="addItemToOrder" parameterOrder="orderid itemid quantity"> <input message="tns:addItemToOrderRequest" name="addItemToOrderRequest"/> <output message="tns:addItemToOrderResponse" name="addItemToOrderResponse"/> </operation> </portType> ... </definitions>
In this case, each message is defined by its parts, each of which is of a specific type. The type for each message is defined in terms of XML Schema types, which actually gives us a great degree of flexibility. In this case we're dealing with only simple values, but it's also possible to create a service that expects an XML structure. For example, we can add a schema section:
<?xml version="1.0" encoding="UTF-8"?> <definitions name="CandyOrder-binding" targetNamespace="http://www.candyorder.com/definitions/CandyOrderRemoteInterface" xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://www.candyorder.com/definitions/CandyOrderRemoteInterface" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <types> <schema targetNamespace= "http://www.candyorder.com/definitions/CandyOrderRemoteInterface" xmlns="http://www.w3.org/2000/10/XMLSchema"> <element name="orderAddition"> <complexType> <sequence> <element name="orderid" type="int"/> <element name="itemid" type="string"/> <element name="quantity" type="int"/> </sequence> </complexType> </element> </schema> </types> <message name="completeOrderRequest"> <part name="orderid" type="xsd:int"/> </message> <message name="completeOrderResponse"> <part name="result" type="xsd:string"/> </message> <message name="createOrderRequest"> <part name="custid" type="xsd:string"/> </message> <message name="createOrderResponse"> <part name="result" type="xsd:int"/> </message> <message name="addItemToOrderRequest"> <part name="body" element="tns:orderAddition"/> </message> <message name="addItemToOrderResponse"> <part name="result" type="xsd:boolean"/> </message> ...
In this way, you can create services that require (or return) complex messages.
WSDL isn't limited to defining SOAP messages. You can use WSDL to define messages that are sent using SMTP or other protocols, as well. Check out some of the resources for more possibilities.
WSDL 1.2 is currently at the Working Draft level, and makes several changes. For example portTypes have been renamed as intefaces, and ports are now called endpoints. Make sure you know what version your system is expecting.