Web services. Introduction to WSDL. February 23, 2006.
-
Upload
bernice-conley -
Category
Documents
-
view
219 -
download
0
Transcript of Web services. Introduction to WSDL. February 23, 2006.
Web services.
Introduction to WSDL.
February 23, 2006.
Today.
● Introduction to WSDL.● Soap revisited and exercises.● Midterm.
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.
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.
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).
Abstract (interface) WSDL part
TYPES
MESSAGES
OPERATIONS
PORT TYPES
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.
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”
Concrete WSDL part
BINDINGS.
SERVICES AND PORTS.
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.
EBNF-style WSDL specification.
<definitions> { <documentation> .. </documentation> }
{ <import> .. </import> }
[ <types> .. </types> ]
{ <message> .. </message> }
{ <portType> .. </portType> }
{ <binding> .. </binding> }
{ <service> .. </service> }
</definitions>
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!
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" >
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.
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!
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!
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!
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>
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.
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).
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.
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>
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.
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>
Alternative priseCheckRequest
<message name="PriceCheckRequest"> <part name"sku" type="xsd:string" />
</message>
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>
The <types> element
The place for the WSDL document to define user-defined XML types and elements.
At most (1) types element!
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!
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.
<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..
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>
<binding> element name
Convention: portTypeName ++ protolname(++ binding)
where the protocol name is where to the binding maps.
portType name must be unique!
The <port> element
Specifies the endpoint hosting the web service.
Naming rule: unique among all ports in the same WSDL document.
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.
The <service> element
Purpose: contain a set of related ports!
Conventionally:
● one service per WSDL document!● Different addresses for each port in a service!
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:
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
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.