Intro to web services


Published on

Published in: Technology
  • Be the first to comment

No Downloads
Total Views
On Slideshare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

Intro to web services

  1. 1. Introduction to Web Services Sabyasachi Ghosh [email_address]
  2. 2. Agenda <ul><li>Refresher: Networking/OSI Model </li></ul><ul><li>Socket Programming </li></ul><ul><li>Remote Procedure Calls </li></ul><ul><li>Refresher: XML </li></ul><ul><li>Overview of XML RPC </li></ul><ul><li>Introduction to Web Services/SOA </li></ul><ul><li>Introduction to SOAP </li></ul><ul><li>Refresher: HTTP </li></ul><ul><li>Restful Architectures and RESTful Web Services </li></ul><ul><li>Q&A </li></ul>
  3. 3. Client-Server Technology CLIENT SERVER NETWORK Request Request Request Response Response
  4. 4. The OSI Model
  5. 5. Introduction to Sockets <ul><li>Socket is an endpoint of a bidirectional inter-process communication flow across an IP-based computer network. </li></ul><ul><li>Sockets are provided by the operating system and is mapped by the OS to a communicating application process or thread. </li></ul><ul><li>The transport layer comprises two types of protocols, TCP (Transport Control Protocol) and UDP (User Datagram Protocol). </li></ul><ul><ul><li>The most widely used programming interfaces for these protocols are sockets. </li></ul></ul>
  6. 6. Sockets Sockets are generalized form of inter-process communication (IPC)
  7. 7. RPC – Remote Procedure Calls <ul><li>Remote Procedure Call (RPC) is an inter-process communication that allows a computer program to cause a subroutine or procedure to execute in another address space. </li></ul><ul><li>RPC (Remote Procedure Call) goes back at least as far as 1976, when it was described in RFC 707. </li></ul>Ref: Wikipedia
  8. 8. RPC – How does it work ? <ul><li>A client makes a call to the procedure in a remote machine (server) which has the business logic with appropriate parameters. </li></ul><ul><li>The server receives the parameters and executes the procedure locally and then transmits the results back to the client. </li></ul><ul><li>The client receives the results. </li></ul>
  9. 9. RPC – More formally: <ul><li>The client calls the Client stub. The call is a local procedure call, with parameters pushed on to the stack in the normal way. </li></ul><ul><li>The client stub packs the parameters into a message and makes a system call to send the message. Packing the parameters is called marshalling. </li></ul><ul><li>The kernel sends the message from the client machine to the server machine. </li></ul><ul><li>The kernel passes the incoming packets to the server stub. </li></ul><ul><li>Finally, the server stub calls the server procedure. The reply traces the same in other direction. </li></ul>Ref: Wikipedia
  10. 10. XML: Introduction <ul><li>eXtensible Markup Language </li></ul><ul><li>A simplified version of SGML [ Standard Generalized Markup Language ] </li></ul><ul><li>Maintains the most useful parts of SGML </li></ul><ul><li>Designed so that SGML can be delivered over the Web </li></ul><ul><li>More flexible and adaptable than HTML </li></ul>Markup: Information added to a text to make its structure comprehensible
  11. 11. XML: Differences with HTML <ul><li>XML was designed to carry data, not displaying data </li></ul><ul><li>XML is not a replacement for HTML. </li></ul><ul><li>Different goals: </li></ul><ul><ul><li>XML was designed to describe data and to focus on what data is. </li></ul></ul><ul><ul><li>HTML was designed to display data and to focus on how data looks. </li></ul></ul><ul><li>HTML is about displaying information, XML is about describing information. </li></ul>
  12. 12. XML: Example <?xml version=&quot;1.0&quot;?> < catalog > < product category = &quot;mobile phone&quot;> <mfg>Nokia</mfg><model>8890</model> <description> Intended for EGSM 900 and GSM 1900 networks … </description> <clock setting= &quot;nist&quot; alarm = &quot;yes&quot;/> </ product > < product category = &quot;mobile phone&quot;> <mfg>Ericsson</mfg><model>A3618</model> <description>...</description> </ product > </ catalog >
  13. 13. XML: More on it <ul><li>XML is a metalanguage, not a specific language. </li></ul><ul><li>Defines the rules how to mark up a document - does not define the names used in markup. </li></ul><ul><li>Includes capability to prescribe a XML Schema (XSD) to constrain the markup permitted in a class of documents. </li></ul><ul><li>Intended for all natural languages, regardless of character set, orientation of script, etc. </li></ul>
  14. 14. XML RPC
  15. 15. JSON <ul><li>Object: collection of comma separated Attributes </li></ul><ul><ul><li>var object = { } </li></ul></ul><ul><li>Attributes: name-value pairs </li></ul><ul><ul><li>“ name”: “Duke” </li></ul></ul><ul><ul><li>“ age”: 10 </li></ul></ul><ul><li>Array: List of comma separated objects </li></ul><ul><ul><li>[{“name”: “Duke”, “age”: 10}, {name:“Tux”, “age”: 20}] </li></ul></ul><ul><li>Data types </li></ul><ul><ul><li>(String, Number, boolean, array, object, null) </li></ul></ul>
  16. 16. { &quot;firstName&quot;: &quot;John&quot;, &quot;lastName&quot;: &quot;Smith&quot;, &quot;age&quot;: 25, &quot;address&quot;: { &quot;streetAddress&quot;: &quot;21 2nd Street&quot;, &quot;city&quot;: &quot;New York&quot;, &quot;state&quot;: &quot;NY&quot;, &quot;postalCode&quot;: &quot;10021&quot; }, &quot;phoneNumber&quot;: [ { &quot;type&quot;: &quot;home&quot;, &quot;number&quot;: &quot;212 555-1234&quot; }, { &quot;type&quot;: &quot;fax&quot;, &quot;number&quot;: &quot;646 555-4567&quot; } ] }
  17. 17. What is a Web Service <ul><li>A web service is a piece of business logic, located somewhere on the Internet, that is accessible through standard-based Internet protocols such as HTTP or SMTP. </li></ul><ul><li>Using a web service could be as simple as logging into a site or as complex as facilitating a multi-organization business negotiation. Ex: Creating a Sales Order and initiating a workflow. </li></ul>Ref: Java Web Services, Chappel et al, O'Reilly
  18. 18. Web Services: Alternate definition <ul><li>A web service is just a web page meant for a computer to request and process. </li></ul><ul><li>More precisely, a Web service is a Web page that’s meant to be consumed by an autonomous program as opposed to a Web browser or similar UI tool. </li></ul>Copyright 2005 John Cowan under GPL
  19. 19. Service Oriented Architecture <ul><li>As per Wikipedia, Service-oriented architecture (SOA) is a flexible set of design principles used during the phases of systems development and integration in computing. </li></ul><ul><li>A system based on a SOA will package functionality as a suite of interoperable services that can be used within multiple separate systems from several business domains. </li></ul>
  20. 20. Service Oriented Architecture Requestor Providers Registry FIND , UDDI BIND , SOAP/WSDL PUBLISH, UDDI
  21. 21. Components of SOA <ul><li>Participants: </li></ul><ul><ul><li>Provider </li></ul></ul><ul><ul><li>Registry (broker) </li></ul></ul><ul><ul><li>Requestor </li></ul></ul><ul><li>Interactions: </li></ul><ul><ul><li>Publishing </li></ul></ul><ul><ul><ul><li>Direct </li></ul></ul></ul><ul><ul><ul><li>HTTP GET request </li></ul></ul></ul><ul><ul><ul><li>Dynamic discovery </li></ul></ul></ul><ul><ul><li>Service location (finding) </li></ul></ul><ul><ul><li>Binding </li></ul></ul>
  22. 22. SOA: Publishing (dynamic) Provider Registry Here is my service !
  23. 23. SOA: Locating Service Requestor Registry Where is the service? Find it here !
  24. 24. SOA: Binding Requestor Registry How can I access ? Here is how ! Provider What is the temperature today? 40 C
  25. 25. Characteristics of a Web Service <ul><li>XML-based </li></ul><ul><li>Loosely coupled </li></ul><ul><li>Coarse-grained </li></ul><ul><li>Ability to be synchronous or asynchronous </li></ul><ul><li>Supports Remote Procedure Calls </li></ul><ul><li>Supports document exchange </li></ul>Ref: Java Web Services, Chappel et al, O'Reilly
  26. 26. Major Technologies for WS <ul><li>SOAP – Simple Object Access Protocol </li></ul><ul><li>WSDL – Web Services Definition/Description Language </li></ul><ul><li>UDDI –Universal Description, Discovery, and Integration </li></ul>Ref: Java Web Services, Chappel et al, O'Reilly
  27. 27. SOAP <ul><li>SOAP stands for Simple Object Access Protocol. It is based on XML. </li></ul><ul><li>It is a wired protocol and was defined to be highly interoperable. </li></ul><ul><li>As of today there are extensive libraries support in virtually all languages to support SOAP based communication. </li></ul>
  28. 28. SOAP: Layers SOAP-ENV:Envelope SOAP-ENV:Header SOAP-ENV:Body
  29. 29. SOAP: Example POST /InStock HTTP/1.1 Host: Content-Type: application/soap+xml; charset=utf-8 Content-Length: 299 <?xml version=&quot;1.0&quot;?> < soap:Envelope xmlns:soap=&quot;;> < soap:Header > </ soap:Header > < soap:Body > <m:GetStockPrice xmlns:m=&quot;;> <m:StockName>IBM</m:StockName> </m:GetStockPrice> </ soap:Body > </ soap:Envelope >
  30. 30. Creating a SOAP message <student> <roll>120</roll> <firstName>Kiran</firstName> <lastName>Reddy</lastName> <grades> <english>A</english> <maths>B</maths> </grades> </student> <?xml version=&quot;1.0&quot;?> <soap:Envelope xmlns:soap=&quot;;> <soap:Header> </soap:Header> <soap:Body> <student> <roll>120</roll> <firstName>Kiran</firstName> <lastName>Reddy</lastName> <grades> <english>A</english> <maths>B</maths> </grades> </student> </soap:Body> </soap:Envelope>
  31. 31. SOAP: Envelop <ul><li>The SOAP envelope declaration is simply the outermost XML tag that delineates the boundaries of the SOAP document. </li></ul><ul><li>The following envelope tag shows three required attributes, which specify the namespace and the schema to be used for this envelope: </li></ul><ul><li><SOAP-ENV:Envelope </li></ul><ul><li>xmlns:SOAP-ENV=&quot;; </li></ul><ul><li>xmlns:xsi=&quot;; </li></ul><ul><li>xmlns:xsd=&quot;;> </li></ul><ul><li>... </li></ul><ul><li></SOAP-ENV:Envelope> </li></ul>
  32. 32. SOAP: Header & Body <ul><li>The SOAP header and body are syntactically similar. </li></ul><ul><li>It is simply a place to put directives to the SOAP processor that receives the message. </li></ul><ul><li>The sending and receiving parties need to agree on which elements go there and what they mean. </li></ul>
  33. 33. SOAP: Fault <ul><li>SOAP errors are handled using a specialized envelope known as a Fault Envelope. </li></ul><ul><li>If an error occurs while the server processes a SOAP message, it constructs a SOAP Fault and sends it back to the client. </li></ul>
  34. 34. RESTful Architecture
  35. 35. HTTP: Introduction <ul><li>The Hypertext Transfer Protocol (HTTP) is an application-level protocol for distributed, collaborative, hypermedia information systems. </li></ul><ul><li>HTTP has been in use by the World-Wide Web global information initiative since 1990. </li></ul>
  36. 36. HTTP: How does it work? <ul><li>The HTTP protocol is a request/response protocol. </li></ul><ul><li>A client sends a request to the server in the form of a request method, URI, and protocol version, followed by a MIME-like message containing request modifiers, client information, and possible body content over a connection with a server. </li></ul>
  37. 37. HTTP: How does it work? <ul><li>The server responds with a status line, including the message's protocol version and a success or error code, followed by a MIME-like message containing server information, entity meta information, and possible entity-body content. </li></ul>
  38. 38. HTTP: Request/Response Client Request GET /vnav/labs/PHP/HTTP.php HTTP/1.1 Host: User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv: Gecko/20110218 Firefox/3.6.14 (.NET CLR 3.5.30729) Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 ... Server Response HTTP/1.1 200 OK Server: Apache/1.3.41 (Unix) Content-type: application/xhtml+xml; charset=UTF-8 ...
  39. 39. What is REST? <ul><li>REST stands for Representational State Transfer. </li></ul><ul><li>Its basically a stateless communication protocol relying on lightweight protocols like HTTP. </li></ul><ul><li>It is basically an architectural design methodology. </li></ul>
  40. 40. REST: The other verbs <ul><li>GET to retrieve information </li></ul><ul><li>POST to add new information, showing its relation to old information </li></ul><ul><li>PUT to update information </li></ul><ul><li>DELETE to discard information </li></ul>
  41. 41. RESTful Application Cycle Resources are identified by URIs ↓ Clients communicate with resources via requests using astandard set of methods ↓ Requests and responses contain resource representations informats identified by media types ↓ Responses contain URIs that link to further resources
  42. 42. REST: Give Everything an ID <ul><li>ID is a URI </li></ul><ul><li> </li></ul><ul><li> </li></ul><ul><li> </li></ul><ul><li> </li></ul>
  43. 43. Q & A Thank You!
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.