Web services. Introduction to WSDL. February 23, 2006.

38
Web services. Introduction to WSDL. February 23, 2006.

Transcript of Web services. Introduction to WSDL. February 23, 2006.

Page 1: Web services. Introduction to WSDL. February 23, 2006.

Web services.

Introduction to WSDL.

February 23, 2006.

Page 2: Web services. Introduction to WSDL. February 23, 2006.

Today.

● Introduction to WSDL.● Soap revisited and exercises.● Midterm.

Page 3: Web services. Introduction to WSDL. February 23, 2006.

Calling a web service.

Service requester will need a servicedescription. Three options: ● a textual description of the service,● include sample message formats in the

documentation, or● a formal service description,

in order to send a SOAP request message.

Page 4: Web services. Introduction to WSDL. February 23, 2006.

What to specify.●Ordinary middleware: service operations, (service name, service signature).

●Web services: service access mechanisms (transport protocol, service location)

Summary:

●service interface,●protocol binding,●endpoint address information.

Page 5: Web services. Introduction to WSDL. February 23, 2006.

Web service specification structure.

WSDL (XML document).

Abstract part

Concrete part Protocol bindings,endpoints / ports..

Interface of supportedoperations: service name,service signature (in-out parameters).

Page 6: Web services. Introduction to WSDL. February 23, 2006.

Abstract (interface) WSDL part

TYPES

MESSAGES

OPERATIONS

PORT TYPES

Page 7: Web services. Introduction to WSDL. February 23, 2006.

The abstract WSDL part.

● Types. Data structures for the units (parts) which are exchanged.

● Messages. Consists of parts.

● Operations. Define the transmission primitives/ interactions.

● Port types. Assembles operations in related groups.

Page 8: Web services. Introduction to WSDL. February 23, 2006.

Example: Price check service.

Purpose: extending the “inventoryCheck” web service to include price informatin, and availability.

Wrapped in an operation:

Request message: “product SKU number” Response message: “price” and “available units”

Page 9: Web services. Introduction to WSDL. February 23, 2006.

Concrete WSDL part

BINDINGS.

SERVICES AND PORTS.

Page 10: Web services. Introduction to WSDL. February 23, 2006.

The Concrete WSDL part

● Interface bindings. Specifies message encoding (SOAP encoded or literal), interaction style (RPC or document), and protocol binding per port type.

● Ports. Locations. Specifies EndPoint or network address where the implementation of the port type can be accessed.

● Services. Logical groupings of ports.

Page 11: Web services. Introduction to WSDL. February 23, 2006.

EBNF-style WSDL specification.

<definitions> { <documentation> .. </documentation> }

{ <import> .. </import> }

[ <types> .. </types> ]

{ <message> .. </message> }

{ <portType> .. </portType> }

{ <binding> .. </binding> }

{ <service> .. </service> }

</definitions>

Page 12: Web services. Introduction to WSDL. February 23, 2006.

The XML Schema for WSDL

Any WSDL document must conform tothe XML Schema at

http://schemas.xmlsoap.org/wsdl/2003-02-11.xsd

Try to download it!

Page 13: Web services. Introduction to WSDL. February 23, 2006.

The <definitions> element

<definitions name="PriceCheck" targetNameSpace= "http://www.skatestown.com/services/PriceCheck" xmlns:pc="http://www.skatestown.com/services/PriceCheck"xmlns:avail="http://www.skatestow .com/ns/availability"xmlns:wsi="http://ws-i.org/schemas/conformanceClaim/"xmlns:xsd="http://www.w3.org/2001/XMLSchema"xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"xmlns="http://schemas.xmlsoap.org/wsdl" >

Page 14: Web services. Introduction to WSDL. February 23, 2006.

The <portType> element.

Describes the interface to a web serviceas a “collection of operations”

There may be 0 or more...Best practice: 1 portType definition per

WSDL document.

Page 15: Web services. Introduction to WSDL. February 23, 2006.

Example

<port type name="PriceCheckPortType"> <operation name="checkPrice"> <input message="pc:PriceCheckRequest"/> <output message="pc:PriceCheckResponse"/> </operation></portType>

Naming convention: nameOfWebServicePortType

Must be unique within the WSDL document!

Page 16: Web services. Introduction to WSDL. February 23, 2006.

The <operation> elements

Equivalent to a method signature in Java,defines a “method” on the web service:

●name of the method, (name attribute)●input parameters (input message)●output/return type (output and fault messages)

Naming rule: all operation names are different!

Page 17: Web services. Introduction to WSDL. February 23, 2006.

The <message> element.

Abstract form of an input, output, or fault message.

Defined by a collection of parts.

There may be 0 or more ...

Naming rule: each message name is unique!

Page 18: Web services. Introduction to WSDL. February 23, 2006.

Example

<!-- A PriceCheckRequest is simply an item code (sku) -->

<message name="PriceCheckRequest"> <part name"sku" element="avail:sku" /></message>

<!-- A PriceCheckRequest is simply an item code (sku) -->

<message name="PriceCheckResponse"> <part name="result" element="avail:StockAvailability"/></message>

Page 19: Web services. Introduction to WSDL. February 23, 2006.

The <part> element

Are the components/units of messages.

Has two characterizing properties:

● a name (name attribute -- unique!)● a kind (type attribute or element attribute)

where type -- XSD schema type systemand element -- element in the XML schema.

Page 20: Web services. Introduction to WSDL. February 23, 2006.

Example

<!-- A PriceCheckRequest is simply an item code (sku) -->

<message name="PriceCheckRequest"> <part name"sku" element="avail:sku" /></message>

<!-- A PriceCheckRequest is simply an item code (sku) -->

<message name="PriceCheckResponse"> <part name="result" element="avail:StockAvailability"/></message>

defined in the priceCheck WSDL document (listing 4.1).

Page 21: Web services. Introduction to WSDL. February 23, 2006.

The element attribute.

Specifies the payload of the message on the wire.Must be the XML element which conforms tothe XML schema defined in the types section.

See Listing 4.1.

Page 22: Web services. Introduction to WSDL. February 23, 2006.

Example: PriceCheckRequest message.

<env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance>

<env:Body> <sku xmlns="http://www.skatestown.com/ns/availability">133</sku> </env:Body></env:Envelope>

Page 23: Web services. Introduction to WSDL. February 23, 2006.

The part element attribute

Its value must refer to :

● global XML element, declared in an XML schema in the types section of the WSDL.

● same, but imported in the types section.

Page 24: Web services. Introduction to WSDL. February 23, 2006.

Example: PriceCheckResponse message

<env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <env:Body> <StockAvailability xmlns= "http://www.skatestown.com/ns/availability"> <sku>133</sku> <price>100.0</price> <quantityAvailable xmlns="">12</quantityAvailable> </StockAvailability> </env:Body></env:Envelope>

Page 25: Web services. Introduction to WSDL. February 23, 2006.

Alternative priseCheckRequest

<message name="PriceCheckRequest"> <part name"sku" type="xsd:string" />

</message>

Page 26: Web services. Introduction to WSDL. February 23, 2006.

PriceCheckerRequest message

<env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <env:Body> <ns1:checkPrice env:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns1="http://www.skatestown.com/services/PriceCheck" > <sku xsi:type="xsd:string">133</sku> </ns1:checkPrice> </env:Body></env:Envelope>

Page 27: Web services. Introduction to WSDL. February 23, 2006.

The <types> element

The place for the WSDL document to define user-defined XML types and elements.

At most (1) types element!

Page 28: Web services. Introduction to WSDL. February 23, 2006.

Example of imported types.

<types> <xsd:schema> <!-- assumes XSD file is in the same directory -->

<xsd:import> namespace="http://www.skatestown.com/ns/invoice" schemalocation="http://www.skatestown.com/schema/invoice.xsd"/>

<xsd:import> namespace="http://www.skatestown.com/ns/po" schemalocation="http://www.skatestown.com/schema/po.xsd"/> </xsd:schema></types>

No target namespace because all types are imported!

Page 29: Web services. Introduction to WSDL. February 23, 2006.

The <binding> element

● <portType> defines the web service (ws) operations abstractly: possibly the ws-name, the input types and output types.

● Yet to specifiy the binding to SOAP, the “implementation” requirements.

● How to format messages in a protocol specific manner.

Page 30: Web services. Introduction to WSDL. February 23, 2006.

<binding elements...

A <portType> can have many <binding>s.

A <binding> describes how to invoke using

a specific message/transport protocol:

●SOAP/HTTP●SOAP/SMTP●other..

Page 31: Web services. Introduction to WSDL. February 23, 2006.

Example<binding name="PriceCheckSOAPBinding" type="pc:PriceCheckPortType">

<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http" /> <operation name="checkPrice"> <soap:operation soapAction= "http://www.skatestown.com/services/PriceCheck/checkPrice"/>

<input> <soap:body use="literal" /> </input>

<output> <soap:body use="literal"/> </output>

</operation></binding>

Page 32: Web services. Introduction to WSDL. February 23, 2006.

<binding> element name

Convention: portTypeName ++ protolname(++ binding)

where the protocol name is where to the binding maps.

portType name must be unique!

Page 33: Web services. Introduction to WSDL. February 23, 2006.

The <port> element

Specifies the endpoint hosting the web service.

Naming rule: unique among all ports in the same WSDL document.

Page 34: Web services. Introduction to WSDL. February 23, 2006.

PriceCheckSoapBinding

<port name="PriceCheck" binding="pc:PriceCheckSOAPBinding">

<soap:address location="http://www.skatestown.com/services/PriceCheck"/>

</port>

Attribute "location" gives the URL where messages are send to.

Page 35: Web services. Introduction to WSDL. February 23, 2006.

The <service> element

Purpose: contain a set of related ports!

Conventionally:

● one service per WSDL document!● Different addresses for each port in a service!

Page 36: Web services. Introduction to WSDL. February 23, 2006.

Exercises today:

1. Repeat the soap-encoding and validation exercise from last time for (a) the simple graph of Figure 3.6 p.141, and (b) an array

structure of sibling names, ordered after their age. (Get validation.zip with ftp://evarose.net)

2. Write some possible SOAP requests in RPC interaction style for the method

headers:

Page 37: Web services. Introduction to WSDL. February 23, 2006.

Exercise today

2. (cont)

public double sum(double a1, double a2)

public String getName(int ssn);

3. investigate the web service WSDLs on http://www.xmethods.net

Page 38: Web services. Introduction to WSDL. February 23, 2006.

See you next week.

The midterm exam is given next time (March 2).

We'll continue with WSDL (Chap 4)and on calling a web service.