Top Banner
Web Services Web Services Aug’10 – Dec ’10
24

Web Services

Jan 03, 2016

Download

Documents

renee-barlow

Web Services. Aug’10 – Dec ’10 . Introduction. Web Services enable objects on one computer to call and make use of objects on other computers – distributed computing Chapter includes ❑ What a remote procedure call (RPC) is, and what RPC protocols exist currently - PowerPoint PPT Presentation
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Web Services

Web ServicesWeb Services

Aug’10 – Dec ’10

Page 2: Web Services

Introduction

Web ServicesWeb Services enable objects on one computer to call and enable objects on one computer to call and make use of objects on other computers – make use of objects on other computers – distributed distributed computingcomputingChapter includesChapter includes

❑ ❑ What a remote procedure call (RPC) is, and what RPC protocols What a remote procedure call (RPC) is, and what RPC protocols exist currentlyexist currently

❑ ❑ Why web services can provide more flexibility than previous Why web services can provide more flexibility than previous RPC protocolsRPC protocols

❑ ❑ How XML-RPC worksHow XML-RPC works

❑ ❑ Why most web services implementations should use HTTP as a Why most web services implementations should use HTTP as a transport protocol, and how HTTP works under the hoodtransport protocol, and how HTTP works under the hood

❑ ❑ How the specifications that surround web services fit togetherHow the specifications that surround web services fit together

Aug’10 – Dec ’10

Page 3: Web Services

What Is RPC?What Is RPC?When code on one computer calls code on another computer, When code on one computer calls code on another computer, this is called a this is called a remote procedure call (RPC)remote procedure call (RPC)

Aug’10 – Dec ’10

Page 4: Web Services

What you should know:

❑ ❑ Where does the code you want to call reside? Where does the code you want to call reside?

❑ ❑ Does the code need any parameters? what type? Does the code need any parameters? what type?

❑ ❑ Will the procedure return any data? in what format? Will the procedure return any data? in what format?

Aug’10 – Dec ’10

Page 5: Web Services

RPC protocolsRPC protocols

set of rules that enables different applications, or set of rules that enables different applications, or even different computers, to communicate.even different computers, to communicate.

DCOMDCOM (Distributed Component Object Model) (Distributed Component Object Model) and IIOP and IIOP (Internet Inter-ORB Protocol) – based on COM and CORBA (Internet Inter-ORB Protocol) – based on COM and CORBA respectively and JAVA RMI.respectively and JAVA RMI. Protocols specify Protocols specify

how to provide an address for the remote computer,how to provide an address for the remote computer, how to package data to be sent to the remote how to package data to be sent to the remote

procedures,procedures, how to retrieve a response, how to retrieve a response, how to initiate the call,how to initiate the call, how to deal with errors, how to deal with errors, etc etc

Aug’10 – Dec ’10

Page 6: Web Services

DCOM- Distributed Component Object ModelDCOM- Distributed Component Object Model

Extenxtion of Microsoft’s Extenxtion of Microsoft’s Component Object Component Object Model Model component-based softwarecomponent-based software can write a COM object in virtually any can write a COM object in virtually any programming languageprogramming language ex: ex: Microsoft OfficeMicrosoft Office major drawback: Microsoft specific!major drawback: Microsoft specific!

Aug’10 – Dec ’10

Page 7: Web Services

IIOP :IIOP : Internet Inter-ORB ProtocolInternet Inter-ORB Protocol

Common Object Request Broker Architecture, or Common Object Request Broker Architecture, or CORBACORBA any CORBA object can talk to any other enabling any CORBA object can talk to any other enabling components to run on different platformscomponents to run on different platforms

Neither COM nor CORBA are easy to work with!Neither COM nor CORBA are easy to work with!““DLL hellDLL hell “ - “ - (mismatched incompatible versions of libraries (mismatched incompatible versions of libraries of a machine)of a machine)

Aug’10 – Dec ’10

Page 8: Web Services

Java RMIJava RMI

Remote Method Invocation Remote Method Invocation

Java RMI can do one thing DCOM and IIOP can’t: Java RMI can do one thing DCOM and IIOP can’t:

It can transfer code with every call It can transfer code with every call

drawback to Java RMI: ties the programmer to one drawback to Java RMI: ties the programmer to one programming languageprogramming language

Aug’10 – Dec ’10

Page 9: Web Services

The New RPC Protocol: The New RPC Protocol: Web ServicesWeb Services

a a web service web service is a service that accepts a request is a service that accepts a request and returns data or carries out a processing taskand returns data or carries out a processing task

XML web services: XML web services: atleast request or response consists of XMLatleast request or response consists of XML

two main designs for XML Web services:two main designs for XML Web services: XML-RPCXML-RPC a a document approachdocument approach

Aug’10 – Dec ’10

Page 10: Web Services

XML-RPC (Remote Procedure Call)XML-RPC (Remote Procedure Call)

calling a remote procedure by specifying the calling a remote procedure by specifying the procedure to call and the parameters to passprocedure to call and the parameters to pass

Client sends command encoded in XMLClient sends command encoded in XML Server performs RPC, returns response in XMLServer performs RPC, returns response in XML

Internet Topic ExchangeInternet Topic Exchange

Aug’10 – Dec ’10

Page 11: Web Services

The Target APIThe Target API

three available methods:three available methods:

1.1. struct topicExchange.getChannels()struct topicExchange.getChannels()

2.2. struct topicExchange.ping(string topicName, struct topicExchange.ping(string topicName, struct details)struct details)

3.3. struct topicExchange.getChannelInfo(string struct topicExchange.getChannelInfo(string topicName)topicName)

Aug’10 – Dec ’10

Page 12: Web Services

A Simple RequestA Simple Request

<<methodCallmethodCall>>

<<methodNamemethodName>>

topicExchange.getChannelstopicExchange.getChannels

</</methodNamemethodName>>

</</methodCallmethodCall>>

Passing ParameterPassing Parameter

<methodCall><methodCall>

<methodName>topicExchange.ping</methodName><methodName>topicExchange.ping</methodName>

<<paramsparams>>

<<paramparam>>

<value><string>books</string></value><value><string>books</string></value>

</</paramparam>>

</</paramsparams>>

</methodCall></methodCall> Aug’10 – Dec ’10

Page 13: Web Services

Using a struct : named valuesUsing a struct : named values<methodCall><methodCall>

<methodName>topicExchange.ping</methodName><methodName>topicExchange.ping</methodName>

<params><params>

<param><param>

<value><string>books</string></value><value><string>books</string></value>

</param></param>

<param><param>

<value><value>

<struct><struct>

<member><member>

<name>blog_name</name><name>blog_name</name>

<value><string>Wiley Today</string></value><value><string>Wiley Today</string></value>

</member></member>

<member><member>

<name>url</name><name>url</name>

<value><value>

<string>http://www.wiley.com/WileyCDA/Section/index.html </string><string>http://www.wiley.com/WileyCDA/Section/index.html </string>

</value></value>

</member></member>

</struct></struct>

</value></value>

</param></param>

</params></params>

</methodCall></methodCall> Aug’10 – Dec ’10

Page 14: Web Services

A struct can have a struct as one or more of its A struct can have a struct as one or more of its membersmembers

<methodResponse><methodResponse>

<params><params>

<param><param>

<value><value>

<<structstruct>>

<member><member>

<name>channels</name><name>channels</name>

<value><value>

<<structstruct>>

<member><member>

<name>books</name><name>books</name>

<value><value>

<<structstruct>>

<member><member>

<name>url</name><name>url</name>

<value><value>

<string>http://topicexchange.com/t/books/</<string>http://topicexchange.com/t/books/</string>string>

</value></value>

</member></member>

</</structstruct>>

</value></value>

</member></member> Aug’10 – Dec ’10

Page 15: Web Services

<member><member>

<name>logic</name><name>logic</name>

<value><value>

<<structstruct>>

<member><member>

<name>url</name><name>url</name>

<value><value>

<string>http://topicexchange.com/t/logic/</string><string>http://topicexchange.com/t/logic/</string>

</value></value>

</member></member>

<</struct/struct>>

</value></value>

</member></member>

<!-- more member elements --><!-- more member elements -->

</</structstruct>>

</value></value>

</member></member>

</</structstruct>>

</value></value>

</param></param>

</params></params>

</methodResponse></methodResponse> Aug’10 – Dec ’10

Page 16: Web Services

The Network TransportThe Network Transport

to send and receive messagesto send and receive messages HTTPHTTP - - Hypertext Transfer Protocol - a request/ response Hypertext Transfer Protocol - a request/ response protocolprotocol

HTTP requestHTTP request: :

1. The client (in most cases, the browser) opens a 1. The client (in most cases, the browser) opens a connection to the HTTP server.connection to the HTTP server.

2. The client sends a request to the server.2. The client sends a request to the server.

3. The server performs some processing.3. The server performs some processing.

4. The server sends back a response.4. The server sends back a response.

5. The connection is closed5. The connection is closed

Aug’10 – Dec ’10

Page 17: Web Services

HTTP message- HTTP message- headersheaders and optional and optional bodybody eacheach header header (simple text) separated from the (simple text) separated from the

next by a new line character next by a new line character bodybody (text or binary) is separated from the (text or binary) is separated from the

headers by two newline charactersheaders by two newline characters A browser request to the server

Aug’10 – Dec ’10

GET /WileyCDA/Section/index.html HTTP/1.1

Accept: */*

Accept-Language: en-us

Accept-Encoding: gzip, deflate

User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Win32)

Host: www.wiley.com

Page 18: Web Services

For a GET request, there is no body in the HTTP messageFor a GET request, there is no body in the HTTP message

A Server ResponseA Server Response

HTTP/1.1 200 HTTP/1.1 200 OKOK

ServerServer: Microsoft-IIS/5.0: Microsoft-IIS/5.0

DateDate: Fri, 09 Mar 2007 15:30:52 GMT: Fri, 09 Mar 2007 15:30:52 GMT

Content-TypeContent-Type: text/html: text/html

Last-ModifiedLast-Modified: Thu, 06 Mar 2007 12:19:57 GMT: Thu, 06 Mar 2007 12:19:57 GMT

Content-LengthContent-Length: 98: 98

<<htmlhtml>>

<head><title>Hello world</title></head><head><title>Hello world</title></head>

<body><body>

<p>Hello world</p><p>Hello world</p>

</body></body>

</</htmlhtml>>

Aug’10 – Dec ’10

Page 19: Web Services

An HTML page with form

<html><html>

<head><head>

<title>Test form</title><title>Test form</title>

</head></head>

<body><body>

<form action=”acceptform.asp” method=”POST”><form action=”acceptform.asp” method=”POST”>

Enter your first name: <input name=”txtFirstName” /><br Enter your first name: <input name=”txtFirstName” /><br />/>

Enter your last name: <input name=”txtLastName” Enter your last name: <input name=”txtLastName” /><br />/><br />

<input type=”submit” /><input type=”submit” />

</form></form>

</body></body>

</html></html>

Aug’10 – Dec ’10

Page 20: Web Services

POST to acceptform.aspPOST to acceptform.asp

POSTPOST /acceptform.asp HTTP/1.1 /acceptform.asp HTTP/1.1

AcceptAccept: */*: */*

RefererReferer: http://www.wiley.com/myform.htm: http://www.wiley.com/myform.htm

Accept-LanguageAccept-Language: en-us: en-us

Content-TypeContent-Type: application/x-www-form-urlencoded: application/x-www-form-urlencoded

Accept-EncodingAccept-Encoding: gzip, deflate: gzip, deflate

User-AgentUser-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Win32): Mozilla/4.0 (compatible; MSIE 7.0; Win32)

HostHost: www.wiley.com: www.wiley.com

Content-LengthContent-Length: 36: 36

txtFirstNametxtFirstName=Joe&txtLastName=Fawcett=Joe&txtLastName=Fawcett

Aug’10 – Dec ’10

Page 21: Web Services

Why HTTP for Web Services?Why HTTP for Web Services?

❑ ❑ HTTP is already a HTTP is already a widely implementedwidely implemented, , and well understood, protocol.and well understood, protocol.

❑ ❑ The The request/response paradigmrequest/response paradigm lends lends itself to RPC well.itself to RPC well.

❑ ❑ Most Most firewallsfirewalls are already configured to are already configured to work with HTTP.work with HTTP.

❑ ❑ HTTP makes it easy to build in security by HTTP makes it easy to build in security by using using Secure Sockets Layer (SSL)Secure Sockets Layer (SSL)..

Aug’10 – Dec ’10

Page 22: Web Services

Request/ResponseRequest/Response

1. Open a connection to the server providing 1. Open a connection to the server providing the XML-RPC service.the XML-RPC service.

2. Send the information on the entry to be 2. Send the information on the entry to be added.added.

3. Process the addition.3. Process the addition.

4. Get back the result, including an error 4. Get back the result, including an error code if it didn’t work, or a ping identifier if it code if it didn’t work, or a ping identifier if it did.did.

5. Close the connection.5. Close the connection.

Aug’10 – Dec ’10

Page 23: Web Services

Using HTTP for XML-RPCUsing HTTP for XML-RPC

Need to do two things with the clientNeed to do two things with the client

1.1. For the HTTP method, use For the HTTP method, use POSTPOST..

2.2. For For the body the body of the message, include an of the message, include an XML document XML document comprising the comprising the XML-RPC requestXML-RPC request

POSTPOST /RPC2 HTTP/1.1 /RPC2 HTTP/1.1

Accept: */* Accept-Language: en-usAccept: */* Accept-Language: en-us

Content-Type: application/x-www-form-urlencodedContent-Type: application/x-www-form-urlencoded

Accept-Encoding: gzip, deflateAccept-Encoding: gzip, deflate

User-Agent: Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 5.0)User-Agent: Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 5.0)

Host: www.wiley.comHost: www.wiley.com

Content-Length: 79Content-Length: 79

<<methodCallmethodCall>>

<methodName>topicExchange.getChannels</methodName><methodName>topicExchange.getChannels</methodName>

</</methodCallmethodCall>> Aug’10 – Dec ’10

Page 24: Web Services

Aug’10 – Dec ’10