What is WSDL?

Download Report

Transcript What is WSDL?

Lab Practice 5
Meilan JIANG ([email protected])
Cyber infrastructure Research Laboratory
Department of Advanced Technology Fusion
Konkuk University
What is WSDL?
• WSDL is Web Services Description Language.
• WSDL define detailed information about web
service.
– The use of XML is a reasonable between a machinereadable and a human-readable document.
•
WSDL document is complex and includes elements
such as imports, types, schemes, messages, ports,
bindings, and services.
WSDL Overview
•
<definitions/>
<types/>
What Data Types?
WSDL document is to state that
it answers four questions about a
web service.
–
–
–
–
<message/>
<portType/>
What Do you Do?
What do you do?
What language do you speak?
How do I talk to you?
Where do I find you?
<binding/>
How?
<service />
Interface
Definition
Where?
Interface
Implementation
WSDL Document
•
This figure shows a high-level
picture of the WSDL specification:
WSDL Document(1/4)
<defnitions />
<types />
WSDL Document(2/4)
<message />
<portType />
WSDL Document(3/4)
< binding />
WSDL Document(4/4)
<service />
A WSDL Document for StockQuote
• We will use the tools provided by Axis to generate
the WSDL document from our Java class as shown
below:
StockQuote.class
http://localhost:8080/axis
services/Stockquote?wsdl
Java Java2WSDL StockQuote
Axis Servlet
Java2WSDL
StockQuote.wsdl
Try it out –Using the Axis servlet(1/2)
• The easiest way to generate a WSDL document
for a web service deployed with Axis is to
navigate to
http://<server-name>/services/<service-name>?wsdl
• When the Axis servlet detects the ?wsdl, it
generates the WSDL based on the class file of
the service.
Try it out –Using the Axis servlet(2/2)
http://localhost:8080/axis/services/StockQuote?wsdl
Try it out – with Java2WSDL(1/2)
• Using the Java2WSDL tool
> java org.apache.axis.wsdl.Java2WSDL
com.wrox.jws.stockquote.StockQuote
-l http://localhost:8080/axis/service/StockQuote
Before, we have to add the following files,
The Xerces(XML parser) files:
xml-apis.jar
xercesImpl.jar
The JAR files distributed with Axis
axis.jar
commons-logging.jar
jaxrpc.jar
wsdl4j.jar
The .class file(not the .java file) of the StockQuote example
Try it out – with Java2WSDL(2/2)
• Here is the Java2WSDL command for creating the
StockQuote.wsdl file
Regardless of the methodology that we use to generate the
WSDL document, the result will be the same.
The <definitions /> Element
•
The root of every WSDL document is the <definitions /> element.
targetNamespace = “http://localhost:8080/axis/services/StockQuote”
•
Describe our web service URL
xmlns:impl="http://stockquote.jws.wrox.com"
xmlns:intf="http://stockquote.jws.wrox.com"
•
These namespaces define the implementation and definition namespaces for StockQuote
•
Conceptually, a web service can be separated in to two WSDL files:
– Document for the definition of the interface of the web service(<types />, <message />,<portType
/>,<bindings />).
– Document for the implementation of the web service(<service />).
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
•
Describe SOAP encoing URL
•
•
•
xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
Desribe SOAP element and XML Schema
The <message /> Element
¤
<message />element gives information about the data that
travels from one endpoint to another.
The getQuote() methods is described in terms
of a request and a response.
• Message compared to Java methods and port
type compared to Java classes.
•
The <portType /> Element
• Describes and defines the operations(or methods)
supported by the web service.
• WSDL supports four modes of operations:
•
•
•
•
One-way
Request-Response
Solicit-Response
Notification
The <portType /> Element
• One-way
(1) messge
Client
Webservice
The <portType /> Element
•
Request-Response
(1) request
Client
Webservice
(2) response
The <portType /> Element
• Solicit-Reponse
(1) Correlated message
Client
Webservice
(2) mesage
The <portType /> Element
• Notification
Client
Webservice
(1) message
The <binding /> Element
• The <binding /> element describes how the
operations defined in a port type are transitted
over the network.
The <service /> Element
•
•
Specifies where to find the web service.
The <service /> element is a collection of <port />
elements.
The <import/ > Element
• <service /> element allows clients to bind to one
well-difined interface and switch implementation
aw sill.
• To satisfy that requirement, the Java2WSDL Axis
tool that we used earlier can be invoked to create
two files: one for the interface definition and one
for the interface implementation as shown in the
nextpage’s diagram:
The import Element
StockQuote.class
java Java2WSDL
StockQuote_interface.wsdl –O
StockQuoteImpl.wsdl
Java2WSDL
StockQuoteImpl.wsdl
StockQuote_interface.wsdl
Try It Out – WSDL Interface Definition Document
•
The following command creates two files,
StockQuoete_interface,wsdl and StockQuoteImpl.wsdl
> java org.apache.axis.wsdl.Java2WSDL
com.wrox.jws.stockquote.StockQuote
–l http://localhost:8080/axis/services/StockQuote
-O StockQuoteImpl.wsdl
- L StockQuote_interface.wsdl
Try It Out – WSDL Interface Definition Document
The StockQuote_Interface.wsdl document is the
Stockquote.wsdl document reviewed earlier.
• The StockQuoteImpl is following WSDL Document.
•
<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions targetNamespace="http://stockquote.jws.wrox.com-impl"
xmlns:apachesoap="http://xml.apache.org/xml-soap" xmlns:impl="http://stockquote.jws.wrox.com-impl"
xmlns:intf="http://stockquote.jws.wrox.com" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<wsdl:import location="StockQuote_interface.wsdl"
namespace="http://stockquote.jws.wrox.com"/>
<wsdl:service name="StockQuoteService">
<wsdl:port binding="intf:StockQuoteSoapBinding" name="StockQuote">
<wsdlsoap:address location="http://localhost:8080/axis/services/StockQuote"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
The <types /> Element
What data types do you use?
This question is answered using the <types/>
elements.
StockQuote.wsdl
Market.wsdl
WSDL-Based Clients
• Using the WSDL documents we have generated, we
will be able to automatically create client classes
that provide an interface to the web service.
StockQuote
(Real Class)
Web Service
Client
Java Call
Java Call
StockQuote
(stub)
SOAP Call
Network
SOAP Call
Axis
Servlet
Try It Out – StockQuoteClient
• Generate the stub and its supporting classes.
• Using WSDL2Java class
– Axis provides this class
Java org.apache.axis.wsdl.WSDL2Java StockQuote.wsdl
¤ WSDL2Java build the stub files
¤ make the classes
Try It Out – StockQuoteClient
• Build the client. The client code is contained in
the StockQuoteClinet class:
Try It Out – StockQuoteClient
•
StockQuote.java (interface)
–
–
•
StockQuoteSoapBindingStub.java
–
•
Stub class, It implements the SDI(StockQuote).
StockQuoteService.java (interface)
–
•
Corresponds to the stockquote portType in the WSDL file.
Service Definition Interface(SDI)
Derived from the <service />element in WSDL.
StockQuoteServiceLocator.java
–
Implements the StockQuoteService interfce.
WSDL Element
Java Class or Interfce
For each element in
A Java class
<type />
<portType />
A Java interface
<binding />
A stub class
<service />
A service interface
A service implementation(the locator)
<fault />
A Java class
Try It Out – StockQuoteClient
StockQuoteClient.java
1
2
3
java com.wrox.jws.stoctquote.StockQuoteClient IBM
1. We get a reference to the
StockQuoteService interface by
creating an instance of the
StockQuoteserviceLocator class:
2. We get 1a reference to the
StockQuote interface:
3. We call the getQuote method
2
as we would call any other
local interface:
3
Summary
• WSDL is an important topic for two reasons.
– First, we want people to be able to read descriptions of the
services that we provide.
– Second, we want tools like WSDL2Java to automatically read a
description and their users with a quick interface
•
Four questions about web services
–
–
–
–
What?
Which?
How?
Where?