Presentation is loading. Please wait.

Presentation is loading. Please wait.

Introduction to Web Services

Similar presentations


Presentation on theme: "Introduction to Web Services"— Presentation transcript:

1 Introduction to Web Services
By J. H. Wang Nov. 28, 2011

2 Outline Overview RESTful Web services

3 What is a Web Service “a method of communication between two electronic devices over the Web” From Wikipedia entry on “Web service” “a software system designed to support interoperable machine-to-machine interaction over a network” From W3C definition

4 Two major classes of Web services
An interface described in a machine-processable format (WSDL, or Web Services Description Language) Other systems interact with the Web service using SOAP messages, typically conveyed using XML/HTTP and other Web-related standards SOAP: Simple Object Access Protocol Two major classes of Web services REST-compliant To manipulate XML representations of Web resources using a uniform set of “stateless” operations Arbitrary

5 Web Services Architecture

6 Simple Object Access Protocol (SOAP)
A protocol for exchanging structured information in the implementation of Web Services XML: for message format HTTP, SMTP: for message transmission

7 SOAP Message POST /InStock HTTP/1.1 Host: Content-Type: application/soap+xml; charset=utf-8 Content-Length: 299 SOAPAction: " <?xml version="1.0"?> <soap:Envelope xmlns:soap=" <soap:Header> </soap:Header> <soap:Body> <m:GetStockPrice xmlns:m=" <m:StockName>IBM</m:StockName> </m:GetStockPrice> </soap:Body> </soap:Envelope>

8 Web APIs Moving from SOAP based services to REST based communications
REST: Representational State Transfer Do not require XML, SOAP, WSDL Typically a defined set of HTTP request messages along with the structure of response messages expressed in XML or JSON format JSON: JavaScript Object Notation They allow the combination of multiple Web services into new applications known as mashups

9 Web Services in a Service-Oriented Architecture

10 Three Most Common Styles of Use
RPC (Remote Procedure Calls) A distributed function call interface SOA (Service-Oriented Architecture) The basic unit of communication is a message, rather than an operation REST (Representational State Transfer) Standard operations in HTTP: GET, POST, PUT, DELETE Interacting with stateful resources, rather than messgaes or operations

11 RPC Web Services Basic unit: WSDL operation
Widely deployed and supported, but not loosely coupled Other approaches: CORBA, DCE/RPC, Java RMI

12 SOA Web Services Basic unit: message
Supported by most major vendors, loose coupling

13 Representational State Transfer (REST)
Interacting with stateful resources, rather than messages or operations Using HTTP standard operations such as GET, POST, PUT, DELETE WSDL 2.0 offers support for binding to all HTTP request methods WSDL 1.1 only GET and POST

14 Representation of concepts in WSDL 1.1 and 2.0 documents

15 Criticisms Too complex, not open source
A custom interface requires a custom client for every service Concerns about performance due to XML and SOAP/HTTP in enveloping and transport

16 RESTful Web Services Introduced by Roy Fielding in his doctoral dissertation He is one of the principal authors of the HTTP specification version 1.0 and 1.1 Client-server Clients initiate requests Servers process requests and return appropriate responses Requests and responses are built around the transfer of representations of resources

17 Constraints Client-server Stateless Cacheable Layered system
No client context is stored on the server between requests The server can be stateful Cacheable Clients can cache responses Layered system Clients cannot tell whether it’s connected directly to the end server, or an intermediary Code on demand (optional) Servers are able to temporarily extend the functionality of a client Uniform interface

18 Guiding Principles of the Interface
Identification of resources E.g. URIs Manipulation of resources through these representations Self-descriptive messages Hypermedia as the engine of application state E.g. hyperlinks, hypertext

19 Key Goals Scalability of component interactions
Generality of interfaces Independent deployment of components Intermediary components to reduce latency, enforce security, and encapsulate legacy systems

20 RESTful Web API Four aspects Base URI for the Web service
Internet media type of the data supported by the Web service E.g. JSON, XML, or YAML The set of operations supported by the Web service using HTTP methods E.g. GET, PUT, POST, or DELETE The API must be hypertext driven

21 No official standard for RESTful services
But Web standard protocols are often used

22 RESTful Web services: Basics
Use HTTP methods explicitly Be stateless Expose directory structure-like URIs Transfer XML, JSON, or both

23 Using HTTP Methods Explicitly
One-to-one mapping GET: to retrieve a resource on the server POST: to create a resource PUT: to change the state of a resource or to update it DELETE: to remove a resource For example, Before GET /adduser?name=Robert HTTP/1.1 After POST /users HTTP/1.1 Host: myserver Content-Type: application/xml <?xml version="1.0"?> <user> <name>Robert</name> </user>

24 Another example Before After
GET /updateuser?name=Robert&newname=Bob HTTP/1.1 After PUT /users/Robert HTTP/1.1 Host: myserver Content-Type: application/xml <?xml version="1.0"?> <user> <name>Bob</name> </user>

25 Be Stateless For scalability, clients are required to send complete, independent requests include all data needed to be fulfilled so that the components in the intermediary servers may forward, route, and load-balance without any state being held locally in between requests

26

27 Expose directory structure-like URIs
Guidelines Hide the server-side scripting technology file extensions (.jsp, .php, .asp), if any, so you can port to something else without changing the URIs Keep everything lowercase Substitute spaces with hyphens or underscores (one or the other) Avoid query strings as much as you can Instead of using the 404 Not Found code if the request URI is for a partial path, always provide a default page or resource as a response.

28 Transfer XML, JSON, or both
Ex. <?xml version="1.0"?> <discussion date="{date}" topic="{topic}"> <comment>{comment}</comment> <replies> <reply href="/discussion/topics/{topic}/joe"/> <reply href="/discussion/topics/{topic}/bob"/> </replies> </discussion> Common MIME types JSON: application/json XML: application/xml XHTML: application/xhtml+xml

29 References http://en.wikipedia.org/wiki/Web_service
RESTful Web services: the basics, by Alex Rodriguez, IBM developerWorks, available at:

30 Thanks for Your Attention!


Download ppt "Introduction to Web Services"

Similar presentations


Ads by Google