CSE 6331 © Leonidas Fegaras Web Services1 Web Services (adapted from Erdogan Dogdu's presentation)...

22
CSE 6331 ©Leonidas Fegaras Web Services 1 Web Services (adapted from Erdogan Dogdu's presentation) Leonidas Fegaras

Transcript of CSE 6331 © Leonidas Fegaras Web Services1 Web Services (adapted from Erdogan Dogdu's presentation)...

Page 1: CSE 6331 © Leonidas Fegaras Web Services1 Web Services (adapted from Erdogan Dogdu's presentation) Leonidas Fegaras.

CSE 6331 ©Leonidas Fegaras Web Services 1

Web Services(adapted from Erdogan Dogdu's presentation)

Leonidas Fegaras

Page 2: CSE 6331 © Leonidas Fegaras Web Services1 Web Services (adapted from Erdogan Dogdu's presentation) Leonidas Fegaras.

CSE 6331 ©Leonidas Fegaras Web Services 2

What are Web Services?

• Services available via the Web– Mostly for application-to-application communication

– Enables business-to-business transactions

• Examples:– stock quote service

– weather service

– map service

– Web search service

• Based on XML

• SOAP: Simple Object Access Protocol

• WSDL: Web Service Description Language

• UDDI: Universal Description, Discovery, and Integration

Page 3: CSE 6331 © Leonidas Fegaras Web Services1 Web Services (adapted from Erdogan Dogdu's presentation) Leonidas Fegaras.

CSE 6331 ©Leonidas Fegaras Web Services 3

SOAP

• A lightweight protocol for exchanging information in a

distributed, heterogeneous environment

• Enables cross-platform interoperability– programming language neutral

– hardware independent

– protocol independent

• Works over existing Internet infrastructure

• Builds on XML standards

• Defines– message format

– data encoding

– headers for sending messages & receiving responses

Page 4: CSE 6331 © Leonidas Fegaras Web Services1 Web Services (adapted from Erdogan Dogdu's presentation) Leonidas Fegaras.

CSE 6331 ©Leonidas Fegaras Web Services 4

A SOAP Request

• SOAP requests are HTTP POST requests

POST /WebCalculator/Calculator.asmx HTTP/1.1Content-Type: text/xmlSOAPAction: “http://tempuri.org/Add”Content-Length: 386

<?xml version=“1.0”?><soap:Envelope ...> ...</soap:Envelope>

Page 5: CSE 6331 © Leonidas Fegaras Web Services1 Web Services (adapted from Erdogan Dogdu's presentation) Leonidas Fegaras.

CSE 6331 ©Leonidas Fegaras Web Services 5

Message Layout

SOAP Message

SOAP Envelope

SOAP Header

SOAP Body

Message Name & Data

Headers

Headers

XML-encoded SOAP

message name

& data

<Body> contains SOAP message name

Individual headers

<Header> encloses headers

<Envelope> encloses payload

Protocol binding headers

The complete SOAP

message

Page 6: CSE 6331 © Leonidas Fegaras Web Services1 Web Services (adapted from Erdogan Dogdu's presentation) Leonidas Fegaras.

CSE 6331 ©Leonidas Fegaras Web Services 6

Message Format

• The SOAP schema can be defined in an XML document

<?xml version=“1.0”?><soap:Envelope ...> <soap:Header ...> ... </soap:Header> <soap:Body> <Add xmlns=“http://tempuri.org/”> <n1>12</n1> <n2>10</n2> </Add> </soap:Body></soap:Envelope>

Page 7: CSE 6331 © Leonidas Fegaras Web Services1 Web Services (adapted from Erdogan Dogdu's presentation) Leonidas Fegaras.

CSE 6331 ©Leonidas Fegaras Web Services 7

Server Response

HTTP/1.1 200 OK...Content-Type:text/xmlContent-Length: 391

<?xml version=“1.0”?><soap:Envelope ...> <soap:Body> <AddResult xmlns=“http://tempuri.org/”> <result>28.6</result> </AddResult> </soap:Body></soap:Envelope>

Page 8: CSE 6331 © Leonidas Fegaras Web Services1 Web Services (adapted from Erdogan Dogdu's presentation) Leonidas Fegaras.

CSE 6331 ©Leonidas Fegaras Web Services 8

Data are in XML

<soap:Envelope ...> <soap:Body> <GetStockDataResult xmlns=“http://tempuri.org/”> <result> <Description>Plastic Novelties Ltd</Description> <Price>129</Price> <Ticker>PLAS</Ticker> </result> </GetStockDataRseult> </soap:Body></soap:Envelope>

Page 9: CSE 6331 © Leonidas Fegaras Web Services1 Web Services (adapted from Erdogan Dogdu's presentation) Leonidas Fegaras.

CSE 6331 ©Leonidas Fegaras Web Services 9

Example of a Request

POST /StockQuote HTTP/1.1Host: www.stockquoteserver.comContent-Type: text/xml; charset="utf-8"Content-Length: nnnnSOAPAction: "Some-URI“

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" SOAP-ENV: encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"> <SOAP-ENV:Body> <m:GetLastTradePrice xmlns:m="Some-URI"> <symbol>DIS</symbol> </m:GetLastTradePrice> </SOAP-ENV:Body></SOAP-ENV:Envelope>

Page 10: CSE 6331 © Leonidas Fegaras Web Services1 Web Services (adapted from Erdogan Dogdu's presentation) Leonidas Fegaras.

CSE 6331 ©Leonidas Fegaras Web Services 10

Example of a Response

HTTP/1.1 200 OKContent-Type: text/xml; charset="utf-8"Content-Length: nnnn

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" SOAP-ENV: encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/> <SOAP-ENV:Body> <m:GetLastTradePriceResponse xmlns:m="Some-URI"> <Price>34.5</Price> </m:GetLastTradePriceResponse> </SOAP-ENV:Body></SOAP-ENV:Envelope>

Page 11: CSE 6331 © Leonidas Fegaras Web Services1 Web Services (adapted from Erdogan Dogdu's presentation) Leonidas Fegaras.

CSE 6331 ©Leonidas Fegaras Web Services 11

WSDL: Web Services Description Language

• XML schema for describing Web Services– Service interface definition

• abstract semantics for Web Service

– Service implementation definition

• concrete end points and network addresses where Web Service can be invoked

• Used primarily (although not exclusively) to describe SOAP

services

• Describes four critical pieces of data:– Interface information describing all publicly available functions

– Data type information for all message requests and message responses

– Binding information about the transport protocol to be used

– Address information for locating the specified service

Page 12: CSE 6331 © Leonidas Fegaras Web Services1 Web Services (adapted from Erdogan Dogdu's presentation) Leonidas Fegaras.

CSE 6331 ©Leonidas Fegaras Web Services 12

Main Structure

<definition namespace = “http/… “>

<type> xschema types </type>

<message> … </message>

<port> a set of operations </port>

<binding> communication protocols </binding>

<service> a list of binding and ports </service>

<definition>

Page 13: CSE 6331 © Leonidas Fegaras Web Services1 Web Services (adapted from Erdogan Dogdu's presentation) Leonidas Fegaras.

CSE 6331 ©Leonidas Fegaras Web Services 13

WSDL Parts

• <types> define types used in message declaration– XML Schema must be supported by any vendor of WSDL conformant

products

• The <message> element defines the data elements of an operation– each message may consist of one or more parts

• similar to the parameters of a function call in a traditional programming

language

• The <portType> defines a web service, the operations that can be

performed, and the messages that are involved– defines the connection point to a web service, an instance of <portType>.

– similar to a function library in a traditional programming language

– each operation can be compared to a function in a traditional programming

language

Page 14: CSE 6331 © Leonidas Fegaras Web Services1 Web Services (adapted from Erdogan Dogdu's presentation) Leonidas Fegaras.

CSE 6331 ©Leonidas Fegaras Web Services 14

Example: HelloService.wsdl<?xml version="1.0" encoding="UTF-8"?>

<definitions name="HelloService"

targetNamespace="http://www.ecerami.com/wsdl/HelloService.wsdl"

xmlns="http://schemas.xmlsoap.org/wsdl/"

xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"

xmlns:tns="http://www.ecerami.com/wsdl/HelloService.wsdl"

xmlns:xsd="http://www.w3.org/2001/XMLSchema">

<message name="SayHelloRequest">

<part name="firstName" type="xsd:string"/>

</message>

<message name="SayHelloResponse">

<part name="greeting" type="xsd:string"/>

</message>

<portType name="Hello_PortType">

<operation name="sayHello">

<input message="tns:SayHelloRequest"/>

<output message="tns:SayHelloResponse"/>

</operation>

</portType>

Page 15: CSE 6331 © Leonidas Fegaras Web Services1 Web Services (adapted from Erdogan Dogdu's presentation) Leonidas Fegaras.

CSE 6331 ©Leonidas Fegaras Web Services 15

Example (cont.)

<binding name="Hello_Binding" type="tns:Hello_PortType">

<soap:binding style="rpc"

transport="http://schemas.xmlsoap.org/soap/http"/>

<operation name="sayHello">

<soap:operation soapAction="sayHello"/>

<input>

<soap:body

encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"

namespace="urn:examples:helloservice"

use="encoded"/>

</input>

<output>

<soap:body

encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"

namespace="urn:examples:helloservice"

use="encoded"/>

</output>

</operation>

</binding>

Page 16: CSE 6331 © Leonidas Fegaras Web Services1 Web Services (adapted from Erdogan Dogdu's presentation) Leonidas Fegaras.

CSE 6331 ©Leonidas Fegaras Web Services 16

Example (cont.)

<service name="Hello_Service">

<documentation>WSDL File for HelloService</documentation>

<port binding="tns:Hello_Binding" name="Hello_Port">

<soap:address

location="http://localhost:8080/soap/servlet/rpcrouter"/>

</port>

</service>

</definitions>

Page 17: CSE 6331 © Leonidas Fegaras Web Services1 Web Services (adapted from Erdogan Dogdu's presentation) Leonidas Fegaras.

CSE 6331 ©Leonidas Fegaras Web Services 17

WSDL Invocation Tools

• You can use any SOAP method to call HelloService

• Using the GLUE tool:invoke URL method arg1 arg2 arg3...

• To invoke the HelloService with GLUE– place the HelloService.wsdl file within a publicly available directory

– issue the command:

invoke http://localhost:8080/wsdl/HelloService.wsdl sayHello World

• GLUE will – download the specified WSDL file

– invoke the sayHello method

– pass World as a parameter

• Server response:

result = Hello, World!

Page 18: CSE 6331 © Leonidas Fegaras Web Services1 Web Services (adapted from Erdogan Dogdu's presentation) Leonidas Fegaras.

CSE 6331 ©Leonidas Fegaras Web Services 18

UDDI

• UDDI = Universal Description, Discovery, and Integration

• Industry initiative to address discovery– a registration database for Web Services

• Specifications– schema for service providers and descriptions

– API for publishing and searching

– developed on industry standards (XML, HTTP, TCP/IP, SOAP)

– applies to both XML and non-XML services

• Implementation– public and private instances of specification

Page 19: CSE 6331 © Leonidas Fegaras Web Services1 Web Services (adapted from Erdogan Dogdu's presentation) Leonidas Fegaras.

CSE 6331 ©Leonidas Fegaras Web Services 19

Providers, Services and Bindings

• Providers– Examples: Accounting Department, Corporate Application Server

– Name, Description, Contact Information

– Categorization and Identification Information

• Services– Examples: Purchase Order services, Payroll services

– Name, Description(s)

– Categorization Information

• Bindings– Description(s), access points, parameters

– Examples: Access Point (http://...) for Web Service

Page 20: CSE 6331 © Leonidas Fegaras Web Services1 Web Services (adapted from Erdogan Dogdu's presentation) Leonidas Fegaras.

CSE 6331 ©Leonidas Fegaras Web Services 20

Features

• Neutral in terms of protocols– as a registry, it can contain pointers to anything

• Can search by business, service, Web Service, binding

• Usage of Globally Unique Identifiers (GUIDs)

• Specification allows public and private nodes

• Delineation between interface and implementation

Page 21: CSE 6331 © Leonidas Fegaras Web Services1 Web Services (adapted from Erdogan Dogdu's presentation) Leonidas Fegaras.

CSE 6331 ©Leonidas Fegaras Web Services 21

tModel

• <tModel> represents meta-data and interfaces

<tModel xmlns="urn:uddi-org:api" tModelKey="UUID:AAAAAAAA-AAAA-AAAA-AAAA-AAAAAAAAAAAA">

<name>microsoft-com:creditcheck</name> <description xml:lang="en">Check credit limits</description> <overviewDoc> <overviewURL>http://schema.com/creditcheck.wsdl </overviewURL> </overviewDoc> <categoryBag> <keyedReference tModelKey="UUID:CD153257-086A-4237-B336-6BDCBDCC6634" keyName="Consumer credit gathering or reporting services" keyValue="84.14.16.01.00"/> <keyedReference tModelKey="UUID:C1ACF26D-9672-4404-9D70-39B756E62AB4" keyName="types" keyValue="wsdlSpec"/> </categoryBag></tModel>

Page 22: CSE 6331 © Leonidas Fegaras Web Services1 Web Services (adapted from Erdogan Dogdu's presentation) Leonidas Fegaras.

CSE 6331 ©Leonidas Fegaras Web Services 22

bindingTemplate

• A bindingTemplate represents data and implementation details

<bindingTemplate serviceKey="33c3d124-e967-4ab1-8f51-d93d95fac91a" bindingKey="48f2bc6b-a6de-4be8-9f2b-2342aeafaaac">

<accessPoint URLType="http">http://localhost/HelloWorld/Service1.asmx

</accessPoint> <tModelInstanceDetails> <tModelInstanceInfo tModelKey="uuid:64c756d1-3374-

4e00-ae83-ee12e38fae63“/> </tModelInstanceDetails> </bindingTemplate>