You are on page 1of 23

Session 2

Web Services Description Language (WSDL)

Review of Session 1 (1 of 2)

Web Services are self-contained, self-describing, modular applications that can be published, located and invoked across the Web. The service interface in a Web Service helps the Web Service to be called by any other application program or another Web Service. A Web Service should be registered in a service registry to be accessed by other programs. Web Services use the standard Web protocols to communicate unlike COM, RMI, JINI, or CORBA. XML messages are used to interchange information between the service and the application program.
XML Web Services with Java / Session 2 / 2 of 23

Review of Session 1 (2 of 2)

A service provider along with a service registry, a service broker and a service requestor form the important participants in a Web Service. A Web Service architecture primarily consists of the following layers:

Data store Data access Web Service logic Web Service logic facade Listener layer

XML Web Services with Java / Session 2 / 3 of 23

Session Objectives

Justify the need for a service description language Describe WSDL Discuss a simple Web service and its WSDL file Describe WSDL terminologies Analyze a WSDL file Explain the role of SOAP in WSDL

XML Web Services with Java / Session 2 / 4 of 23

Service Description Language (SDL)


Platform A Service 1 . . . Description of service written in SDL

Specifies functionality of service Platform B Compatibility Issues Lists the parameters required by the exposed method Lists parameters returned by methods Documents the Web service contract (messages that the Web Service will generate and accept)
XML Web Services with Java / Session 2 / 5 of 23

Service 2
. . .

Web Service Description Language (WSDL) (1)


Web Service XML file describing Web services acts as a contract between the Web service consumer and the Web service

Web Service Consumer

XML Web Services with Java / Session 2 / 6 of 23

Web Service Description Language (WSDL) (2)


WSDL Document

Network Accessible Service Specification Language (NASSL)

Well Defined Service Document (WDS)

Specifies non-operational information for a XML based Interface Definition service viz. service category, expiry date, Language used to specify operational company name etc. information for a Web Service.
XML Web Services with Java / Session 2 / 7 of 23

A Simple Web Service Interface

Output in XML format can be consumed by other Web services


XML Web Services with Java / Session 2 / 8 of 23

The WSDL File


Namespaces
<?xml version="1.0" encoding="utf-8" ?> - <definitions xmlns:s="http://www.w3.org/2001/XMLSchema ..... xmlns="http://schemas.xmlsoap.org/wsdl/"> + <types> + <message name="addSoapIn"> ......................... + <message name="addHttpPostOut"> + <portType name="TestWSSoap"> .......................... + <portType name="TestWSHttpPost"> + <binding name="TestWSSoap" type="s0:TestWSSoap"> ......................... + <binding name="TestWSHttpPost type="s0:TestWSHttpPost"> + <service name="TestWS"> </definitions>

elements
XML Web Services with Java / Session 2 / 9 of 23

WSDL Terminologies (1)


SOAP Operation
SOAP Request

Ports
SOAP Response CLIENT Web Service

HTTP Request HTTP Response HTTP Operation


XML Web Services with Java / Session 2 / 10 of 23

Ports

WSDL Terminologies (2)


message: Abstract definition of the data being communicated types: Mechanism to define data type used in Web service operation: Abstract definition of a particular action supported
Web service

by the

port:

An end-point described by the combination of a network address and binding

portType: Collection of operations binding: Specification that lists the communication protocol and the data
format for a particular port type

service: Defined as a collection of ports

XML Web Services with Java / Session 2 / 11 of 23

The Analysis of a WSDL File

definitions element is the root component of the WSDL file

XML Web Services with Java / Session 2 / 12 of 23

Elements of a WSDL File


Abstract Definitions
Platform and Language Independent

Concrete Definitions
Machine or Language Specific

types

messages

portTypes

bindings

services

modifies

ports

operations

XML Web Services with Java / Session 2 / 13 of 23

types

Describes data types used for exchanging messages by the service.

- <types> - <s:schema attributeFormDefault=qualified elementFormDefault=qualified targetNamespace=http://tempuri.org/> - <s:element name=add> - <s:complexType> - <s:sequence> ...... </s:sequence> </s:complexType> </s:element> ..... </s:schema> </types>
XML Web Services with Java / Session 2 / 14 of 23

message

Specifies the services request and response mechanism Not dependent upon any protocol i.e. there is no naming convention for message names. Divided into parts and each part is defined by the <part> element
- <message name="addSoapIn"> <part name="parameters" element="s0:add" /> </message> - <message name="addSoapOut"> <part name="parameters" element="s0:addResponse" /> </message> ........
XML Web Services with Java / Session 2 / 15 of 23

portType

Operations (input output messages) are to be defined by specifying the <operation> element portType defines operations provided by the Web Service.

<portType name="TestWSSoap"> - <operation name="add"> <input message="s0:addSoapIn" /> <output message="s0:addSoapOut" /> </operation> </portType> ......................
XML Web Services with Java / Session 2 / 16 of 23

binding

Represents the concrete descriptions of the operations Specifies the representation of parameters for a Web method

<binding name="TestWSSoap" type="s0:TestWSSoap"> <soap:binding transport= http://schemas.xmlsoap.org/soap/http style="document" /> -<operation name="add"> <soap:operation soapAction=http://tempuri.org/add style="document" /> - <input><soap:body use="literal" /></input> - <output><soap:body use="literal" /></output> </operation> </binding> .......
XML Web Services with Java / Session 2 / 17 of 23

service

Specifies methods offered by the Web service Services are available on ports, which have specific addresses

<service name="TestWS"> - <port name="TestWSSoap" binding="s0:TestWSSoap"> <soap:address location="http://localhost/ws.asmx" /> </port> - <port name="TestWSHttpGet" binding="s0:TestWSHttpGet"> <http:address location="http://localhost/ws.asmx" /> </port> ..... </service>

XML Web Services with Java / Session 2 / 18 of 23

SOAP
Lightweight protocol that can be used over HTTP, SMTP etc.

Can be easily adapted with firewalls

Standard for communicating with Web services

WSDL specifies the protocols supported by a Web service

XML Web Services with Java / Session 2 / 19 of 23

Sample Code (SOAP Request)


POST /ws.asmx HTTP/1.1 Host: localhost Content-Type: text/xml; charset=utf-8 Content-Length: length SOAPAction: "http://tempuri.org/add" <?xml version="1.0" encoding="utf-8"?> <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd=http://www.w3.org/2001/XMLSchema xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> <soap:Body> Replace with <add xmlns="http://tempuri.org/"> actual values <a>int</a> <b>int</b> </add> </soap:Body> </soap:Envelope>

XML Web Services with Java / Session 2 / 20 of 23

Sample Code (SOAP Response)


HTTP/1.1 200 OK Content-Type: text/xml; charset=utf-8 Content-Length: length <?xml version="1.0" encoding="utf-8"?> <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap= "http://schemas.xmlsoap.org/soap/envelope/"> Replace with <soap:Body> actual values <addResponse xmlns="http://tempuri.org/"> <addResult>int</addResult> </addResponse> </soap:Body> </soap:Envelope>

XML Web Services with Java / Session 2 / 21 of 23

Summary (1 of 2)

The language used to describe a service is known as Service Description Language (SDL). The language used to describe the services offered by a Web Service is known as Web Service Description Language (WSDL). WSDL is a subset of two separate documents, NASSL (Network Accessible Service Specification Language) and WDS (Well Defined Service document). An operation is an abstract definition of a particular action supported by the Web Service. A set of input and output messages collectively defines an operation.

XML Web Services with Java / Session 2 / 22 of 23

Summary (2 of 2)

types is a mechanism to define the data types used

in the Web Service. For example, XSD (XML Style Definition). binding specifies a list of communication protocols and data formats for a particular port type. A binding specifies the manner in which operations will access the service using a certain protocol. A WSDL file can be classified into two sections:

Abstract Definitions Concrete Descriptions

XML Web Services with Java / Session 2 / 23 of 23

You might also like