introduction to web services by j. h. wang nov. 28, 2011
TRANSCRIPT
![Page 1: Introduction to Web Services By J. H. Wang Nov. 28, 2011](https://reader036.vdocument.in/reader036/viewer/2022062404/5516c085550346a25b8b605a/html5/thumbnails/1.jpg)
Introduction to Web Services
By J. H. Wang
Nov. 28, 2011
![Page 2: Introduction to Web Services By J. H. Wang Nov. 28, 2011](https://reader036.vdocument.in/reader036/viewer/2022062404/5516c085550346a25b8b605a/html5/thumbnails/2.jpg)
Outline
• Overview
• RESTful Web services
![Page 3: Introduction to Web Services By J. H. Wang Nov. 28, 2011](https://reader036.vdocument.in/reader036/viewer/2022062404/5516c085550346a25b8b605a/html5/thumbnails/3.jpg)
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
![Page 4: Introduction to Web Services By J. H. Wang Nov. 28, 2011](https://reader036.vdocument.in/reader036/viewer/2022062404/5516c085550346a25b8b605a/html5/thumbnails/4.jpg)
• Web service– An interface described in a machine-processable form
at (WSDL, or Web Services Description Language)– Other systems interact with the Web service using SO
AP 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
![Page 5: Introduction to Web Services By J. H. Wang Nov. 28, 2011](https://reader036.vdocument.in/reader036/viewer/2022062404/5516c085550346a25b8b605a/html5/thumbnails/5.jpg)
Web Services Architecture
![Page 6: Introduction to Web Services By J. H. Wang Nov. 28, 2011](https://reader036.vdocument.in/reader036/viewer/2022062404/5516c085550346a25b8b605a/html5/thumbnails/6.jpg)
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
![Page 7: Introduction to Web Services By J. H. Wang Nov. 28, 2011](https://reader036.vdocument.in/reader036/viewer/2022062404/5516c085550346a25b8b605a/html5/thumbnails/7.jpg)
SOAP Message• POST /InStock HTTP/1.1
Host: www.example.org Content-Type: application/soap+xml; charset=utf-8 Content-Length: 299 SOAPAction: "http://www.w3.org/2003/05/soap-envelope" <?xml version="1.0"?> <soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope"> <soap:Header> </soap:Header> <soap:Body> <m:GetStockPrice xmlns:m="http://www.example.org/stock"> <m:StockName>IBM</m:StockName> </m:GetStockPrice> </soap:Body> </soap:Envelope>
![Page 8: Introduction to Web Services By J. H. Wang Nov. 28, 2011](https://reader036.vdocument.in/reader036/viewer/2022062404/5516c085550346a25b8b605a/html5/thumbnails/8.jpg)
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
![Page 9: Introduction to Web Services By J. H. Wang Nov. 28, 2011](https://reader036.vdocument.in/reader036/viewer/2022062404/5516c085550346a25b8b605a/html5/thumbnails/9.jpg)
Web Services in a Service-Oriented Architecture
![Page 10: Introduction to Web Services By J. H. Wang Nov. 28, 2011](https://reader036.vdocument.in/reader036/viewer/2022062404/5516c085550346a25b8b605a/html5/thumbnails/10.jpg)
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, DEL
ETE– Interacting with stateful resources, rather than messg
aes or operations
![Page 11: Introduction to Web Services By J. H. Wang Nov. 28, 2011](https://reader036.vdocument.in/reader036/viewer/2022062404/5516c085550346a25b8b605a/html5/thumbnails/11.jpg)
RPC Web Services
• Basic unit: WSDL operation• Widely deployed and supported, but not loosely
coupled• Other approaches: CORBA, DCE/RPC, Java
RMI
![Page 12: Introduction to Web Services By J. H. Wang Nov. 28, 2011](https://reader036.vdocument.in/reader036/viewer/2022062404/5516c085550346a25b8b605a/html5/thumbnails/12.jpg)
SOA Web Services
• Basic unit: message
• Supported by most major vendors, loose coupling
![Page 13: Introduction to Web Services By J. H. Wang Nov. 28, 2011](https://reader036.vdocument.in/reader036/viewer/2022062404/5516c085550346a25b8b605a/html5/thumbnails/13.jpg)
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
![Page 14: Introduction to Web Services By J. H. Wang Nov. 28, 2011](https://reader036.vdocument.in/reader036/viewer/2022062404/5516c085550346a25b8b605a/html5/thumbnails/14.jpg)
Representation of concepts in WSDL 1.1 and 2.0 documents
![Page 15: Introduction to Web Services By J. H. Wang Nov. 28, 2011](https://reader036.vdocument.in/reader036/viewer/2022062404/5516c085550346a25b8b605a/html5/thumbnails/15.jpg)
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
![Page 16: Introduction to Web Services By J. H. Wang Nov. 28, 2011](https://reader036.vdocument.in/reader036/viewer/2022062404/5516c085550346a25b8b605a/html5/thumbnails/16.jpg)
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
![Page 17: Introduction to Web Services By J. H. Wang Nov. 28, 2011](https://reader036.vdocument.in/reader036/viewer/2022062404/5516c085550346a25b8b605a/html5/thumbnails/17.jpg)
Constraints
• Client-server• Stateless
– 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 serv
er, or an intermediary
• Code on demand (optional)– Servers are able to temporarily extend the functionality of a clien
t
• Uniform interface
![Page 18: Introduction to Web Services By J. H. Wang Nov. 28, 2011](https://reader036.vdocument.in/reader036/viewer/2022062404/5516c085550346a25b8b605a/html5/thumbnails/18.jpg)
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
![Page 19: Introduction to Web Services By J. H. Wang Nov. 28, 2011](https://reader036.vdocument.in/reader036/viewer/2022062404/5516c085550346a25b8b605a/html5/thumbnails/19.jpg)
Key Goals
• Scalability of component interactions
• Generality of interfaces
• Independent deployment of components
• Intermediary components to reduce latency, enforce security, and encapsulate legacy systems
![Page 20: Introduction to Web Services By J. H. Wang Nov. 28, 2011](https://reader036.vdocument.in/reader036/viewer/2022062404/5516c085550346a25b8b605a/html5/thumbnails/20.jpg)
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
![Page 21: Introduction to Web Services By J. H. Wang Nov. 28, 2011](https://reader036.vdocument.in/reader036/viewer/2022062404/5516c085550346a25b8b605a/html5/thumbnails/21.jpg)
• No official standard for RESTful services– But Web standard protocols are often used
![Page 22: Introduction to Web Services By J. H. Wang Nov. 28, 2011](https://reader036.vdocument.in/reader036/viewer/2022062404/5516c085550346a25b8b605a/html5/thumbnails/22.jpg)
RESTful Web services: Basics
• Use HTTP methods explicitly
• Be stateless
• Expose directory structure-like URIs
• Transfer XML, JSON, or both
![Page 23: Introduction to Web Services By J. H. Wang Nov. 28, 2011](https://reader036.vdocument.in/reader036/viewer/2022062404/5516c085550346a25b8b605a/html5/thumbnails/23.jpg)
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.1Host: myserverContent-Type: application/xml<?xml version="1.0"?><user>
<name>Robert</name></user>
![Page 24: Introduction to Web Services By J. H. Wang Nov. 28, 2011](https://reader036.vdocument.in/reader036/viewer/2022062404/5516c085550346a25b8b605a/html5/thumbnails/24.jpg)
• Another example– Before
• 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>
![Page 25: Introduction to Web Services By J. H. Wang Nov. 28, 2011](https://reader036.vdocument.in/reader036/viewer/2022062404/5516c085550346a25b8b605a/html5/thumbnails/25.jpg)
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
![Page 26: Introduction to Web Services By J. H. Wang Nov. 28, 2011](https://reader036.vdocument.in/reader036/viewer/2022062404/5516c085550346a25b8b605a/html5/thumbnails/26.jpg)
![Page 27: Introduction to Web Services By J. H. Wang Nov. 28, 2011](https://reader036.vdocument.in/reader036/viewer/2022062404/5516c085550346a25b8b605a/html5/thumbnails/27.jpg)
Expose directory structure-like URIs
• Ex.– http://www.myservice.org/discussion/topics/{topic}– http://www.myservice.org/discussion/2008/12/10/{topic}
• Guidelines– Hide the server-side scripting technology file extensions (.jsp, .p
hp, .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 othe
r)– 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.
![Page 28: Introduction to Web Services By J. H. Wang Nov. 28, 2011](https://reader036.vdocument.in/reader036/viewer/2022062404/5516c085550346a25b8b605a/html5/thumbnails/28.jpg)
Transfer XML, JSON, or both
• Ex.– <?xml version="1.0"?>
<discussion date="{date}" topic="{topic}"><comment>{comment}</comment><replies>
<reply from="[email protected]" href="/discussion/topics/{topic}/joe"/>
<reply from="[email protected]"href="/discussion/topics/{topic}/bob"/>
</replies></discussion>
• Common MIME types– JSON: application/json– XML: application/xml– XHTML: application/xhtml+xml
![Page 29: Introduction to Web Services By J. H. Wang Nov. 28, 2011](https://reader036.vdocument.in/reader036/viewer/2022062404/5516c085550346a25b8b605a/html5/thumbnails/29.jpg)
References
• http://en.wikipedia.org/wiki/Web_service
• RESTful Web services: the basics, by Alex Rodriguez, IBM developerWorks, available at: http://www.ibm.com/developerworks/webservices/library/ws-restful/.
![Page 30: Introduction to Web Services By J. H. Wang Nov. 28, 2011](https://reader036.vdocument.in/reader036/viewer/2022062404/5516c085550346a25b8b605a/html5/thumbnails/30.jpg)
Thanks for Your Attention!