33
WSDL Kanda Runapongsa ([email protected] ) Dept. of Computer Engineering Khon Kaen University

WSDL Kanda Runapongsa ([email protected])[email protected] Dept. of Computer Engineering Khon Kaen University

Embed Size (px)

Citation preview

Page 1: WSDL Kanda Runapongsa (krunapon@kku.ac.th)krunapon@kku.ac.th Dept. of Computer Engineering Khon Kaen University

WSDL

Kanda Runapongsa ([email protected])

Dept. of Computer EngineeringKhon Kaen University

Page 2: WSDL Kanda Runapongsa (krunapon@kku.ac.th)krunapon@kku.ac.th Dept. of Computer Engineering Khon Kaen University

168493: XML and Web Services (II/2546)

2

What is WSDL? WSDL: Web Services Description

Language A document format for precisely

describing Web services A WSDL document tells us how

to use a Web service

Page 3: WSDL Kanda Runapongsa (krunapon@kku.ac.th)krunapon@kku.ac.th Dept. of Computer Engineering Khon Kaen University

168493: XML and Web Services (II/2546)

3

A WSDL Code Generator WSDL is well suited for code

generators, which can read a WSDL document and generate a programmatic interface for accessing a Web service

Example: a JAX-RPC provider uses WSDL 1.1 to generate Java RMI interfaces and network stubs, which can be used to exchange SOAP messages with a Web service

Page 4: WSDL Kanda Runapongsa (krunapon@kku.ac.th)krunapon@kku.ac.th Dept. of Computer Engineering Khon Kaen University

168493: XML and Web Services (II/2546)

4

A WSDL Code Generator JAX-RPC is not the only

technology that can generate interfaces and network stubs from WSDL document

There are many other code generators, including tools in Microsoft .NET Apace Axis

Page 5: WSDL Kanda Runapongsa (krunapon@kku.ac.th)krunapon@kku.ac.th Dept. of Computer Engineering Khon Kaen University

168493: XML and Web Services (II/2546)

5

A WSDL Code Generator A JAX-RPC toolkit would use a

WSDL document to generate a Java RMI interface (an endpoint interface) and a networking stub that implements the interface

What is Java RMI?

Page 6: WSDL Kanda Runapongsa (krunapon@kku.ac.th)krunapon@kku.ac.th Dept. of Computer Engineering Khon Kaen University

168493: XML and Web Services (II/2546)

6

JAVA RMI RMI: Remote Method Invocation Java-based technology which allows

Java programs to access the objects of another Java program running on a different computer

RMI is a relatively simple protocol, but unlike more complex protocols such as CORBA and DCOM, it works only with Java objects

Page 7: WSDL Kanda Runapongsa (krunapon@kku.ac.th)krunapon@kku.ac.th Dept. of Computer Engineering Khon Kaen University

168493: XML and Web Services (II/2546)

7

Main Pieces of Info in WSDL

WSDL definition contains four important pieces of information about the Web service Interface information describing all

the publicly available functions Data type information for the

incoming (request) and outgoing (response) message to these functions

Page 8: WSDL Kanda Runapongsa (krunapon@kku.ac.th)krunapon@kku.ac.th Dept. of Computer Engineering Khon Kaen University

168493: XML and Web Services (II/2546)

8

Main Pieces of Info in WSDL

Two other important pieces of information about the Web service Binding information about the

protocol to be used for invoking the specified Web service

Address information for locating the specified Web service

Page 9: WSDL Kanda Runapongsa (krunapon@kku.ac.th)krunapon@kku.ac.th Dept. of Computer Engineering Khon Kaen University

168493: XML and Web Services (II/2546)

9

A WSDL Document A WSDL document contains seven

important elements types import message portType operations binding service

These elements are nested in definitions element

Page 10: WSDL Kanda Runapongsa (krunapon@kku.ac.th)krunapon@kku.ac.th Dept. of Computer Engineering Khon Kaen University

168493: XML and Web Services (II/2546)

10

WSDL Important Elements

types Use the XML schema language to

declare complex data types and elements that are used elsewhere in the WSDL document

import Similar to an import element in an

XML schema document; it’s used to import WSDL definitions from other WSDL documents

Page 11: WSDL Kanda Runapongsa (krunapon@kku.ac.th)krunapon@kku.ac.th Dept. of Computer Engineering Khon Kaen University

168493: XML and Web Services (II/2546)

11

WSDL Important Elements

message Describe the message’s payload

using XML schema built-in types Complex types, or elements that are

defined in the WSDL document’s types elements

Elements defined in an external WSDL document the import element refers to

Page 12: WSDL Kanda Runapongsa (krunapon@kku.ac.th)krunapon@kku.ac.th Dept. of Computer Engineering Khon Kaen University

168493: XML and Web Services (II/2546)

12

WSDL Important Elements

portType and operation Describe a Web service’s interface and

define its methods A portType and its operation

elements are analogous to a Java interface and its method declarations

An operation element uses one or more message types to define its input and output payloads

Page 13: WSDL Kanda Runapongsa (krunapon@kku.ac.th)krunapon@kku.ac.th Dept. of Computer Engineering Khon Kaen University

168493: XML and Web Services (II/2546)

13

WSDL Important Elements

binding Assign a portType and its

operation to a particular protocol (for instance, SOAP 1.1) and encoding style

service Responsible for assigning an

Internet address to a specific binding

Page 14: WSDL Kanda Runapongsa (krunapon@kku.ac.th)krunapon@kku.ac.th Dept. of Computer Engineering Khon Kaen University

168493: XML and Web Services (II/2546)

14

WSDL Declarations The XML Declaration

The XML declaration in the sample WSDL document specified a character encoding of UTF-8

<?xml version=“1.0” encoding=“UTF-8”?>

A WSDL document must use either UTF-8 or UTF-16 encoding; other encoding systems are not allowed

Page 15: WSDL Kanda Runapongsa (krunapon@kku.ac.th)krunapon@kku.ac.th Dept. of Computer Engineering Khon Kaen University

168493: XML and Web Services (II/2546)

15

The definitions Element The root element of all WSDL elements

is the definitions element<definitions name=“BookQuoteWS” targetNamespace=“

http://www.Monson-Haefel.com/jwsbook/BookQuote”

xmlns:mh=“http://www.Monson-Haefel.com/jwsbook/BookQuote”

xmlns:soapbind=“http://schemas.xmlsoap.org/wsdl/soap/”

xmlns:xsd=“http://www.w3.org/2001/XMLSchema”

xmlns=“http://schemas.xmlsoap.org/wsdl/”>

Page 16: WSDL Kanda Runapongsa (krunapon@kku.ac.th)krunapon@kku.ac.th Dept. of Computer Engineering Khon Kaen University

168493: XML and Web Services (II/2546)

16

The types Element WSDL adopts the W3C XML schema

built-in types The types element serves as a

container for defining any data types that are not described by the XML schema built-in types

The data types and elements defined in types element are used by message definitions

Page 17: WSDL Kanda Runapongsa (krunapon@kku.ac.th)krunapon@kku.ac.th Dept. of Computer Engineering Khon Kaen University

168493: XML and Web Services (II/2546)

17

<definitions …xmlns:mh=http://abc.com/BQuote”

xmlns=“http://schemas.xmlsoap.org/wsdl”/><types>

<xsd:schema targetnamespace=“http://abc.com/BQuote”>

<xsd:simpleType name=“ISBN”> …

</xsd:simpleType>…</types><message name=“GetBookPriceRequest”>

<part name=“isbn” type=“mh:ISBN”/></message>

…</definitions>

Using Types Defined in the WSDL

types

Page 18: WSDL Kanda Runapongsa (krunapon@kku.ac.th)krunapon@kku.ac.th Dept. of Computer Engineering Khon Kaen University

168493: XML and Web Services (II/2546)

18

The import Element The import element makes available

in the present WSDL document the definition from a specified namespace in another WSDL document

Example, your company may want to maintain WSDL documents for shipping and order processing separately, but present a complete definition of all Web services in a public directory accessible by business partners

Page 19: WSDL Kanda Runapongsa (krunapon@kku.ac.th)krunapon@kku.ac.th Dept. of Computer Engineering Khon Kaen University

168493: XML and Web Services (II/2546)

19

The import Element Example

<definitions name=“AllMhWebServices”xmlns=“http://schemas.xmlsoap.org/wsdl/”>

<import namespace=“http://www.mh.com/jwsbook/BookQuote” location=“http://www.mh.com/jwsbook/BookPrice.wsdl”/>

<import namespace=“http://www.mh.com/jwsbook/po” location=“http://www.mh.com/jwsbook/PurchaseOrder.wsdl”/>

<import namespace=“http://www.mh.com/jwsbook/shipping”location=“http://www.mh.com/jwsbook/wsdl/Shipping.wsdl”/>

Page 20: WSDL Kanda Runapongsa (krunapon@kku.ac.th)krunapon@kku.ac.th Dept. of Computer Engineering Khon Kaen University

168493: XML and Web Services (II/2546)

20

The message Element The message element describes

the payload of a message used by a Web service

The way to define a message element depends on whether you use RPC-style or document-style messaging

Page 21: WSDL Kanda Runapongsa (krunapon@kku.ac.th)krunapon@kku.ac.th Dept. of Computer Engineering Khon Kaen University

168493: XML and Web Services (II/2546)

21

The message Element for RPC-

Style <message

name=“GetBookPriceRequest”><part name=“isbn” type=“xsd:string”/>

</message><message

name=“GetBookPriceResponse”><part name=“price” type=“xsd:float”>

</message>

Page 22: WSDL Kanda Runapongsa (krunapon@kku.ac.th)krunapon@kku.ac.th Dept. of Computer Engineering Khon Kaen University

168493: XML and Web Services (II/2546)

22

The message Element for Document-Style

<definitions … xmlns:mh=“http://www.mh.com/jwsbook/PO”><types>

<xsd:schema targetNamespace=“http://www.mh.com/jwsbook/PO”>

<xsd:import namespace=“http://www.mh.com/jwsbook/PO” schemaLocation=“http://www.mh.com/jwsbook/po.xsd”/>

</xsd:schema></types><message name=“SubmitPurchaseOrderMessage”>

<part name=“order” element=“mh:purchaseOrder”/></message>

Page 23: WSDL Kanda Runapongsa (krunapon@kku.ac.th)krunapon@kku.ac.th Dept. of Computer Engineering Khon Kaen University

168493: XML and Web Services (II/2546)

23

The portType Element A portType element defines the

abstract interface of a Web service It’s a lot like a Java interface

because it defines an abstract type and its method, but not an implementation

In WSDL, the portType is implemented by the binding and service elements

Page 24: WSDL Kanda Runapongsa (krunapon@kku.ac.th)krunapon@kku.ac.th Dept. of Computer Engineering Khon Kaen University

168493: XML and Web Services (II/2546)

24

portType and Java Interface

portType<portType

name=“BookQuote”><operation name=“GetBookPrice”><input name=“isbn” …/><output name=“price” …/></operation>

</portType>

Java Interfacepublic interface

bookQuote {public float getBookPrice(String isbn);

}

Page 25: WSDL Kanda Runapongsa (krunapon@kku.ac.th)krunapon@kku.ac.th Dept. of Computer Engineering Khon Kaen University

168493: XML and Web Services (II/2546)

25

The operation Element The “methods” of the portType

are its operation elements A portType may have one or more

operation elements, each of which defines an RPC- or document-style Web service method

Each operation is composed of input , output, and fault elements

Page 26: WSDL Kanda Runapongsa (krunapon@kku.ac.th)krunapon@kku.ac.th Dept. of Computer Engineering Khon Kaen University

168493: XML and Web Services (II/2546)

26

The operation Element Example

<portType name=“BookQuote”><operation name=“getBookPrice”>

<input name=“isbn” message=“mh:GetBookPriceRequest”/>

<output name=“price” message=“mh:GetBookPriceResponse”/>

<fault name=“InvalidArgumentFault” message=“mh:InvalidArgumentFault”/></operation>

</portType>

Page 27: WSDL Kanda Runapongsa (krunapon@kku.ac.th)krunapon@kku.ac.th Dept. of Computer Engineering Khon Kaen University

168493: XML and Web Services (II/2546)

27

Parameter Order within an Operation <message name=“GetBulkBookPriceRequest”>

<part name=“isbn” type=“xsd:string”/><part name=“quantity” type=“xsd:int”/>

</message>…<portType name=“GetBulkBookPrice”>

<operation name=“getBulkBookPrice” parameterOrder=“isbn quantity”>

<input name=“request” message=“GetBulkBookPriceRequest”/>…

</portType>

Page 28: WSDL Kanda Runapongsa (krunapon@kku.ac.th)krunapon@kku.ac.th Dept. of Computer Engineering Khon Kaen University

168493: XML and Web Services (II/2546)

28

The binding Element The binding element maps an

abstract portType to a set of concrete protocols such as SOAP and HTTP, messaging styles (RPC or document), and encoding styles (Literal or SOAP Encoding)

The binding element and its subelements are used in combination with protocol-specific elements

Page 29: WSDL Kanda Runapongsa (krunapon@kku.ac.th)krunapon@kku.ac.th Dept. of Computer Engineering Khon Kaen University

168493: XML and Web Services (II/2546)

29

The binding Element <definitions …

xmlns=“http://schemas.xmlsoap.org/wsdl/”>

<binding name=“BookPrice_Binding” type=“mh:BookQuote”>…

<operation><input><output>

</operation></binding>

Page 30: WSDL Kanda Runapongsa (krunapon@kku.ac.th)krunapon@kku.ac.th Dept. of Computer Engineering Khon Kaen University

168493: XML and Web Services (II/2546)

30

The binding Element <definitions …

xmlns:soapbind=“http://schemas.xmlsoap.org/wsdl/soap”>

<binding name=“BookPrice_Binding” type=“mh:BookQuote”>

<soapbind:binding style=“rpc”

transport=“http://schemas.xmlsoap.org/soap/http”/>

Page 31: WSDL Kanda Runapongsa (krunapon@kku.ac.th)krunapon@kku.ac.th Dept. of Computer Engineering Khon Kaen University

168493: XML and Web Services (II/2546)

31

The binding Element<operation name=“getBookprice”>

<soapbind:operation style=“rpc”soapAction=“http://www.mh.com/

jwsbook/BookQuote/GetBookPrice”/><input><soapbind:body use=“literal”

namespace=“http://www.mh.com/jwsbook/BookQuote”/>

Page 32: WSDL Kanda Runapongsa (krunapon@kku.ac.th)krunapon@kku.ac.th Dept. of Computer Engineering Khon Kaen University

168493: XML and Web Services (II/2546)

32

The service and port Elements

The service element contains one or more port elements, each of which represents a different Web service

The port element assigns the URL to a specific binding

A service may have more than one port element, each of which assigns a URL to a specific binding

Page 33: WSDL Kanda Runapongsa (krunapon@kku.ac.th)krunapon@kku.ac.th Dept. of Computer Engineering Khon Kaen University

168493: XML and Web Services (II/2546)

33

Defining a service Element

<service name=“BookPriceService”><port name=“BookPrice_Port binding=“mh:BookPrice_Binding”>

<soapbind:address location=http://www.mh.com/jwsbook/BookQuote/></port>

</service>