1 web services web and database management system

32
1 Web Services Web and Database Management System

Upload: blake-long

Post on 05-Jan-2016

217 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: 1 Web Services Web and Database Management System

1

Web Services

Web and Database

Management System

Page 2: 1 Web Services Web and Database Management System

2

Web Services

• Web services are application components

• Web services can be discovered using UDDI

• Web services can be used by other applications

• XML is the basis for Web services

Page 3: 1 Web Services Web and Database Management System

3

Why Web Services?

• Interoperability has Highest Priority– Web-applications are simple applications that run on the web.– They can be used by any browser on any platform

• Web Services take Web-applications to the Next Level– By using Web services, our application can publish its function or

message to the rest of the world

• Web Services have Two Types of Uses– Reusable application-components– Connect existing software

Page 4: 1 Web Services Web and Database Management System

4

How does it work?

• The basic Web services platform is XML + HTTP

• Web services platform elements include:

– SOAP (Simple Object Access Protocol)

– WSDL (Web Services Description Language)

– UDDI (Universal Description, Discovery and Integration)

Page 5: 1 Web Services Web and Database Management System

5

What is WSDL?

• WSDL is an XML-based language for locating and describing Web services

– WSDL stands for Web Services Description Language

– WSDL is based on XML

– WSDL is used to describe Web services

– WSDL is used to locate Web services

Page 6: 1 Web Services Web and Database Management System

6

The WSDL Document Structure

• A WSDL document has these major elements:

Element Defines

<types> The data types used by the web service

<message> The messages used by the web service

<portType> The operations performed by the web service

<binding> The communication protocols used by the web service

Page 7: 1 Web Services Web and Database Management System

7

WSDL document

<definitions> <types>

definition of types........ </types> <message>

definition of a message.... </message> <portType>

definition of a port....... </portType> <binding>

definition of a binding.... </binding></definitions>

Page 8: 1 Web Services Web and Database Management System

8

WSDL Elements

• WSDL Types– The <types> element defines the data types that are used by the

web service.– For maximum platform neutrality, WSDL uses XML Schema

syntax to define data types.

• WSDL Messages– The <message> element defines the data elements of an

operation.– Each message can consist of one or more parts. – The parts can be compared to the parameters of a function call in

a traditional programming language.

Page 9: 1 Web Services Web and Database Management System

9

WSDL Elements (cont)

• WSDL Ports– The <portType> element is the most important WSDL element. – It describes a web service, the operations that can be performed,

and the messages that are involved.– The <portType> element can be compared to a function library (or

a module, or a class) in a traditional programming language.

• WSDL Bindings– The <binding> element defines the message format and protocol

details for each port.

Page 10: 1 Web Services Web and Database Management System

10

WSDL Example

<message name="getTermRequest"> <part name="term" type="xs:string"/></message>

<message name="getTermResponse"> <part name="value" type="xs:string"/></message>

<portType name="glossaryTerms"> <operation name="getTerm">

<input message="getTermRequest"/><output message="getTermResponse"/>

</operation></portType>

Compared to traditional programming: glossaryTerms is a function library, "getTerm" is a function with "getTermRequest" as the input parameter, and getTermResponse as the return parameter.

Page 11: 1 Web Services Web and Database Management System

11

WSDL Port: Operation Types

• The request-response type is the most common operation type, but WSDL defines four types:

Type Definition

One-way The operation can receive a message but will not return a response

Request-response The operation can receive a request and will return a response

Solicit-response The operation can send a request and will wait for a response

Notification The operation can send a message but will not wait for a response

Page 12: 1 Web Services Web and Database Management System

12

One-Way Operation

• A one-way operation example:

<message name="newTermValues"> <part name="term" type="xs:string"/> <part name="value" type="xs:string"/></message>

<portType name="glossaryTerms"><operation name="setTerm"> <input name="newTerm" message="newTermValues"/></operation></portType >

Page 13: 1 Web Services Web and Database Management System

13

Request-Response Operation

• A request-response operation example:

<message name="getTermRequest"> <part name="term" type="xs:string"/></message>

<message name="getTermResponse"> <part name="value" type="xs:string"/></message>

<portType name="glossaryTerms"><operation name="getTerm"> <input message="getTermRequest"/> <output message="getTermResponse"/></operation></portType>

Page 14: 1 Web Services Web and Database Management System

14

Binding to SOAP

<message name="getTermRequest"> <part name="term" type="xs:string"/>< /message>< message name="getTermResponse"> <part name="value" type="xs:string"/>< /message>< portType name="glossaryTerms"> <operation name="getTerm"> <input message="getTermRequest"/> <output message="getTermResponse"/> </operation></portType>

<binding type="glossaryTerms" name="b1"> <soap:binding style="document“ transport="http://schemas.xmlsoap.org/soap/http" /> <operation> <soap:operation soapAction="http://example.com/getTerm"/> <input><soap:body use="literal"/></input> <output><soap:body use="literal"/></output> </operation></binding>

Page 15: 1 Web Services Web and Database Management System

15

What is SOAP?

• SOAP is an XML-based protocol to let applications exchange information over HTTP:

– SOAP is a communication protocol for accessing a Web Service.– SOAP is a format for sending messages– SOAP is platform independent– SOAP is language independent– SOAP is based on XML– SOAP is simple and extensible– SOAP is designed to communicate via Internet– SOAP allows us to get around firewalls

Page 16: 1 Web Services Web and Database Management System

16

Why SOAP?

• Remote Procedure Calls (RPC) like DCOM and CORBA are used to communicated between object– Firewalls and proxy servers will normally block this kind of traffic.

• A better way to communicate between apps is over HTTP – since it is supported by all Internet browsers and servers.

• SOAP provides a way to communicate between applications running on different operating systems, with different technologies and programming languages.

Page 17: 1 Web Services Web and Database Management System

17

SOAP Building Blocks

• A SOAP message is an XML document containing the following elements:

– An Envelope element that identifies the XML document as a SOAP message

– A Header element that contains header information

– A Body element that contains call and response information

– A Fault element containing errors and status information

Page 18: 1 Web Services Web and Database Management System

18

Syntax Rules

• A SOAP message MUST be encoded using XML

• A SOAP message MUST use the SOAP Envelope namespace

• A SOAP message MUST use the SOAP Encoding namespace

• A SOAP message must NOT contain a DTD reference

• A SOAP message must NOT contain XML Processing Instructions

Page 19: 1 Web Services Web and Database Management System

19

Skeleton SOAP Message

<?xml version="1.0"?><soap:Envelopexmlns:soap="http://www.w3.org/2001/12/soap-envelope"soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding"> <soap:Header> ... </soap:Header>

<soap:Body> ... <soap:Fault> ... </soap:Fault> </soap:Body></soap:Envelope>

Page 20: 1 Web Services Web and Database Management System

20

SOAP Envelope Element

• SOAP Envelope element is the root element of a SOAP message

• It defines the XML document as a SOAP message.

<?xml version="1.0"?><soap:Envelopexmlns:soap="http://www.w3.org/2001/12/soap-envelope"soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding"> ... Message information goes here ...</soap:Envelope>

Page 21: 1 Web Services Web and Database Management System

21

SOAP Header Element

• Optional SOAP Header element contains application-specific information (like authentication, payment, etc) about the SOAP message

<?xml version="1.0"?><soap:Envelopexmlns:soap="http://www.w3.org/2001/12/soap-envelope"soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding">

<soap:Header> <m:Trans xmlns:m="http://www.w3schools.com/transaction/" soap:mustUnderstand="1">234 </m:Trans></soap:Header>......</soap:Envelope>

Page 22: 1 Web Services Web and Database Management System

22

The SOAP Body Element

• Required SOAP Body element contains the actual SOAP message intended for the ultimate endpoint of message.

• Immediate child elements of the SOAP Body element may be namespace-qualified

<?xml version="1.0"?><soap:Envelopexmlns:soap="http://www.w3.org/2001/12/soap-envelope"soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding">

<soap:Body> <m:GetPrice xmlns:m="http://www.w3schools.com/prices"> <m:Item>Apples</m:Item> </m:GetPrice></soap:Body>

</soap:Envelope>

Page 23: 1 Web Services Web and Database Management System

23

The SOAP Fault Element

• Optional SOAP Fault element is used to indicate error msg• If a Fault element is present, it must appear as a child

element of the Body element. • A Fault element can only appear once in a SOAP message• SOAP Fault element has the following sub elements:

Sub Element Description

<faultcode> A code for identifying the fault

<faultstring> A human readable explanation of the fault

<faultactor> Information about who caused the fault to happen

<detail> Holds application specific error information related to the Body element

Page 24: 1 Web Services Web and Database Management System

24

SOAP Fault Codes

• The faultcode values defined below must be used in the faultcode element when describing faults:

Error Description VersionMismatch Found an invalid namespace for the SOAP Envelope

element

MustUnderstand An immediate child element of the Header element, with mustUnderstand attribute set to "1", was not understood

Client The message was incorrectly formed or contained incorrect information

Server There was a problem with the server so the message could not proceed

Page 25: 1 Web Services Web and Database Management System

25

SOAP HTTP Binding

• A SOAP method is an HTTP request/response that complies with the SOAP encoding rules.

• A SOAP request could be an HTTP POST or an HTTP GET request

• The HTTP POST request specifies at least two HTTP headers: Content-Type and Content-Length.

HTTP + XML = SOAP

POST /item HTTP/1.1 Content-Type: application/soap+xml; charset=utf-8 Content-Length: 250

Page 26: 1 Web Services Web and Database Management System

26

An Example of SOAP Request

POST /InStock HTTP/1.1Host: www.example.orgContent-Type: application/soap+xml; charset=utf-8Content-Length: nnn

<?xml version="1.0"?><soap:Envelope xmlns:soap="http://www.w3.org/2001/12/soap-envelope" soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding">

<soap:Body xmlns:m="http://www.example.org/stock">  <m:GetStockPrice>    <m:StockName>IBM</m:StockName>  </m:GetStockPrice></soap:Body>

</soap:Envelope>

Page 27: 1 Web Services Web and Database Management System

27

An Example of SOAP Response

HTTP/1.1 200 OKContent-Type: application/soap+xml; charset=utf-8Content-Length: nnn

<?xml version="1.0"?><soap:Envelope xmlns:soap="http://www.w3.org/2001/12/soap-envelope"soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding">

<soap:Body xmlns:m="http://www.example.org/stock">  <m:GetStockPriceResponse>    <m:Price>34.5</m:Price>  </m:GetStockPriceResponse></soap:Body>

</soap:Envelope>

Page 28: 1 Web Services Web and Database Management System

28

SOAP Request and SOAP Response

<?xml version="1.0“ encoding="UTF-8" ?><S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelop/"> <S:Header /> <S:Body>

<ns2:sayHello xmlns:ns2="http://mypackage/"> <arg0>Michael Jordan</arg0></ns2:sayHello>

</S:Body></S:Envelope>

<?xml version="1.0" encoding="UTF-8" ?><S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelop/"> <S:Header /> <S:Body>

<ns2:sayHelloResponse xmlns:ns2="http://mypackage/"> <return>Hello Michael Jordan</return></ns2:sayHelloResponse>

</S:Body></S:Envelope>

Page 29: 1 Web Services Web and Database Management System

29

What is UDDI?

• UDDI is a directory service where companies can register and search for Web services

– UDDI stands for Universal Description, Discovery and Integration

– UDDI is a directory for storing information about web services

– UDDI is a directory of web service interfaces described by WSDL

– UDDI communicates via SOAP

– UDDI is built into the Microsoft .NET platform

Page 30: 1 Web Services Web and Database Management System

30

UDDI

• A UDDI registry is like an electronic phone book for businesses that provide Web Services.

• A UDDI registry is accessed with SOAP messages,– So, a UDDI registry is really just a Web Service

• WSDL provides a standard for describing a Web Service so that we know how to interact with it

• UDDI enables the publication and discovery of Web Service description

Page 31: 1 Web Services Web and Database Management System

31

Types of UDDI

• UDDI registries are categorized into: public and private

• A private UDDI registry is operated by a single organization or a group of collaborating organizations– They are located on large corporate intranets with security control

• Public UDDI registries are freely available for anyone to publish and query over the Internet.– There is a massive public UDDI registry called the UDDI Business

Registry (UBR) that is hosted by IBM, Microsoft, SAP, and NTT.

Page 32: 1 Web Services Web and Database Management System

32

Web Services

ServiceProvider

ServiceConsumer

Directory

Service DescriptionService DescriptionService Description

service request

service response

SOAPSOAP

WSDL

XML