1 / 94

SOAP-based and RESTful Web Services

SOAP-based and RESTful Web Services. Claudio Ochoa, PhD Sr Software Engineer @ Intel. SEG – UNSL September 2007. Agenda.  Web Services  Definition  Advantages and reservations  Classification: SOAP vs REST  SOAP-based WS  XML, XSL, XPath, XSLT  WSDL/ UDDI  SOAP

zenad
Télécharger la présentation

SOAP-based and RESTful Web Services

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. SOAP-based and RESTful Web Services Claudio Ochoa, PhD Sr Software Engineer @ Intel SEG – UNSL September 2007

  2. Agenda  Web Services  Definition  Advantages and reservations  Classification: SOAP vs REST  SOAP-based WS  XML, XSL, XPath, XSLT  WSDL/ UDDI  SOAP  SOA (Service Oriented Architecture)  SOA Benefits  Demo: Creating and consuming a SOAP-based WS INTEL CONFIDENTIAL 2 1/3/2020

  3. Agenda (cont’d)  RESTful WS  AJAX  The XmlHttpRequest object  The HttpRequest object  JSON  JSON data structures  JSON vs XML  Benefits and lowlights of JSON  Generating and Consuming JSON  Demo: JSON and REST-WS INTEL CONFIDENTIAL 3 1/3/2020

  4. Agenda (cont’d) Mashups  Example of mashups  Mashing up a yahoo map object Hands On  Consuming a REST-WS  Creating/Adding a mashup Wrap up INTEL CONFIDENTIAL 4 1/3/2020

  5. Agenda  Web Services  Definition  Advantages and reservations  Classification: SOAP vs REST  SOAP-based WS  XML, XSL, XPath, XSLT  WSDL/ UDDI  SOAP  SOA (Service Oriented Architecture)  SOA Benefits  Demo: Creating and consuming a SOAP-based WS INTEL CONFIDENTIAL 5 1/3/2020

  6. Need for Web Services  Distributed Computing allows sharing information and processing  Traditional distributed processing models assume  Common environment or architecture (J2EE, COM+)  Interoperability is easier to achieve  Distributed processing using different platforms, architectures, and dev languages is complicated  Interoperability between different systems is key  WS are an approach for dealing with this problem INTEL CONFIDENTIAL 6 1/3/2020

  7. Web Services  WS provide a way to access biz or app logic using Internet standard protocols (e.g. HTTP, SMTP, FTP)  Organizations already have communication SW and infrastructure needed to support WS  What are WS for?  Early Internet apps (mail, web sites) helped individuals communicate with each other  WS help applications communicate with each other  WS allow interoperability across independent processing environments and domains INTEL CONFIDENTIAL 7 1/3/2020

  8. WS: advantages  Interaction between different companies systems  Interoperation between apps inside a company  Processing is loosely coupled  No need for common application environment  Do not abandon existing investments in software  Add WS front end to existing apps  Big players (Microsoft, IBM, Sun) are investing in WS and creating tools to support them INTEL CONFIDENTIAL 8 1/3/2020

  9. WS: reservations  WS are not proven technology  Fashionable solution of the day?  SOAP WS rely on XML  XML expands the size of data several times over  More processing is needed to format and parse msgs  Internal apps are now exposed to external threats  WS can expose valuable corporate data, apps, systems… INTEL CONFIDENTIAL 9 1/3/2020

  10. WS: Classification  WS can be classified in two main kinds  SOAP-based WS  RESTful WS  SOAP-based WS have been around for a while  Google (except blogger), enterprise software  RESTful WS are the trendy way for designing WS  Yahoo, Flickr, del.icio.us, pubsub, bloglines, technorati  eBay and Amazon use both REST and SOAP INTEL CONFIDENTIAL 10 1/3/2020

  11. SOAP-based WS: overview  SOAP is a protocol for exchanging XML-based messages over computer networks  SOAP stands for SOAP  Originally stood for Simple Object Access Protocol  Later stood for Service Oriented Architecture Protocol  Provides a basic messaging framework  Successor of XML-RPC (still used for some apps like blogger)  Makes use of Internet transport protocol (HTTP/SMTP) INTEL CONFIDENTIAL 11 1/3/2020

  12. SOAP-based WS (cont’d) Web Services building blocks Web services UDDI WSDL SOAP XML HTTP FTP SMTP Internet Protocols INTEL CONFIDENTIAL 12 1/3/2020

  13. Advantages of SOAP WS  Easier communication behind proxies and firewalls than previous remote execution technology.  Versatile - allows the use of different transport protocols.  Easy to consume (sometimes)  Rigid - type checking, adheres to a contract  Development tools INTEL CONFIDENTIAL 13 1/3/2020

  14. RESTful WS  REST stands for Representational State Transfer  Collection of network architecture principles that outline how resources are defined and addressed  All resources can be uniquely identified by an URI  No need for additional message layer like SOAP  An application interacts with a resource by knowing  the identifier of the resource  the action required  No need to know if there are caches, proxies, gateways, firewalls, tunnels between client and server...  The application needs to understand the format of the information (representation) returned,  HTML, XML, JSON, images… INTEL CONFIDENTIAL 14 1/3/2020

  15. Advantages of Restful WS  Lightweight - not a lot of extra xml markup  Human Readable Results  Improved response times and server loading characteristics  Improves server scalability by reducing the need to maintain communication state.  different servers can be used to handle initial and subsequent requests  A single browser can access any any resource  Easy to build, no toolkits required  Does not require a separate resource discovery mechanism INTEL CONFIDENTIAL 15 1/3/2020

  16. Agenda  Web Services  Definition  Advantages and reservations  Classification: SOAP vs REST  SOAP-based WS  XML, XSL, XPath, XSLT  WSDL/ UDDI  SOAP  SOA (Service Oriented Architecture)  SOA Benefits  Demo: Creating and consuming a SOAP-based WS INTEL CONFIDENTIAL 16 1/3/2020

  17. SOAP-based Web Services  Web services are application components  Web services communicate using open protocols  Web services are self-contained and self- describing  Web services can be discovered using UDDI  Web services can be used by other applications (Interoperability)  XML is the basis for SOAP-Web services INTEL CONFIDENTIAL 17 1/3/2020

  18. XML Overview  XML stands for eXtensible Markup Language.  XML is a markup language much like HTML.  XML tags are not predefined.  XML uses a Document Type Definition (DTD) or an XML Schema to describe the data.  XML with a DTD is designed to be self- descriptive.  XML was designed to store, carry, describe and exchange data. INTEL CONFIDENTIAL 18 1/3/2020

  19. XML elements  Begin with a start tag and end with an end tag <price> 123.45 </price>  Unlike html, every start tag must have a matching end tag  XML elements can be nested <book> <title> Web Services </title> <author> <firstname>John</firstname> <lastname> Doe </lastname> </author> <isbn> 0-471-26716-5 </isbn> </book> INTEL CONFIDENTIAL 19 1/3/2020

  20. XML Syntax  XML documents use a self-describing and simple syntax. <?xml version="1.0" encoding="ISO-8859-1"?> <note> <to>Juan</to> <from>Pedro</from> <heading>Reminder</heading> <body>Don't forget me this weekend!</body> </note>  XML elements are extensible. <note> <date>2002-08-01</date> <to>Juan</to> <from>Pedro</from> <heading>Reminder</heading> <body>Don't forget me this weekend!</body> </note> INTEL CONFIDENTIAL 20 1/3/2020

  21. XML Attributes  XML elements can have attributes.  Attributes are used to provide additional information about elements.  Data can be stored in child elements or in attributes.  <person sex="female"> <firstname>Anna</firstname> <lastname>Smith</lastname> </person>  <person> <sex>female</sex> <firstname>Anna</firstname> <lastname>Smith</lastname> </person> INTEL CONFIDENTIAL 21 1/3/2020

  22. XML Validation Well Formed vs Valid XML  A Well Formed XML document has correct XML syntax. <?xml version="1.0" encoding="ISO-8859-1"?> <note> <to>Tove</to> <from>Jani</from> <heading>Reminder</heading> <body>Don't forget me this weekend!</body> </note>  A Valid XML document also conforms to a DTD. <?xml version="1.0" encoding="ISO-8859-1"?> <!DOCTYPE note SYSTEM "InternalNote.dtd"> <note> <to>Tove</to> <from>Jani</from> <heading>Reminder</heading> <body>Don't forget me this weekend!</body> </note> INTEL CONFIDENTIAL 22 1/3/2020

  23. XML – Other basic concepts  XML Namespaces  Provide a method to avoid element name conflicts.  XML Encoding:  Allow representing extended or foreign characters  XML Parsers:  Provide a way to create and manipulate an XML document.  XML CDATA:  Provide a way to store text data which is ignored by the parser. INTEL CONFIDENTIAL 23 1/3/2020

  24. XSL languages  XSL stands for EXtensible Stylesheet Language  CSS = HTML Style Sheets  XSL = XML Style Sheets  XSL started as a way to describe how XML data should be displayed, but rapidly evolved to 3 main languages:  XSLT - a language for transforming XML documents  XPath - a language for navigating in XML documents  XSL-FO - a language for formatting XML documents INTEL CONFIDENTIAL 25 1/3/2020

  25. XPath  Language for finding information in an XML document.  Is used to navigate through elements and attributes in an XML document.  Syntax for defining parts of an XML document.  Library of standard functions.  W3C Standard. INTEL CONFIDENTIAL 26 1/3/2020

  26. XPath Nodes  In XPath, XML documents are treated as trees of nodes. There are seven types of nodes:  Document (root)  Element  Attribute  Text  Namespace  Processing-instruction  Comment <price>29.99</price> </book> </bookstore <?xml version="1.0" encoding="ISO-8859-1"?> <bookstore> <book> <title lang="en">Harry Potter</title> <author>J K. Rowling</author> <year>2005</year> INTEL CONFIDENTIAL 27 1/3/2020

  27. XPath Syntax  XPath uses path expressions to select nodes or node-sets in an XML document. Path Expression Result /bookstore/* Selects all the child nodes of the bookstore element //* //title[@*] Selects all elements in the document Selects all title elements which have any attribute  XPath wildcards can be used to select unknown XML elements. Wildcard Description * Matches any element node @* Matches any attribute node node() Matches any node of any kind INTEL CONFIDENTIAL 28 1/3/2020

  28. XSLT basics  XSLT is a language for transforming XML docs into XHTML documents or to other XML documents.  XSLT stands for XSL Transformations  XSLT is the most important part of XSL  XSLT uses XPath to navigate in XML documents  XSLT is a W3C Recommendation INTEL CONFIDENTIAL 29 1/3/2020

  29. Web Services Operations Requestors query registry to discover a set of services that it can interact with Providers advertise their services to service registry Service Registry find publish Service Requestor Service Provider bind Requestors negotiate with providers to access and invoke services INTEL CONFIDENTIAL 31 1/3/2020

  30. XML Web Services Framework INTEL CONFIDENTIAL 32 1/3/2020

  31. SOAP  SOAP is a simple XML based protocol to let applications exchange information over HTTP.  Stands for Simple Object Access Protocol.  Protocol for accessing a Web Service.  Platform and language independent.  Allows you to get around firewalls.  A SOAP message MUST be encoded using XML  A SOAP message MUST use the SOAP Envelope namespace  A SOAP message MUST use the SOAP Encoding namespace  A SOAP message must NOT contain a DTD reference  A SOAP message must NOT contain XML Processing Instructions <soap:Envelope xmlns:soap="http://www.w3.org/2001/12/soap-envelope" soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding"> <soap:Header> ... ... </soap:Header> <soap:Body> ... ... <soap:Fault> ... ... </soap:Fault> </soap:Body> </soap:Envelope> INTEL CONFIDENTIAL 33 1/3/2020

  32. SOAP Envelope – Header element  The optional SOAP Header element contains application specific information (like authentication, payment, etc) about the SOAP message.  If the Header element is present, it must be the first child element of the Envelope element. INTEL CONFIDENTIAL 34 1/3/2020

  33. SOAP Envelope – Body element  The required SOAP Body element contains the actual SOAP message intended for the ultimate endpoint of the message.  SOAP Request Envelope  SOAP Response Envelope <soapenv:Envelope xmlns:xsd="http://...."xmlns:soapenv=http://.... xmlns:xsi="http://..."> <soapenv:Body> <ns0:getBalance xmlns:ns0="http://bank.sample“ soapenv:encodingStyle="http://..."> <accountId xsi:type="xsd:int">1</accountId> </ns0:getBalance> </soapenv:Body> </soapenv:Envelope> </soapenv:Envelope> <?xml version="1.0" encoding="UTF-8" ?> <soapenv:Envelope xmlns:soapenv="http://..." xmlns:xsd="http://..." xmlns:xsi="http://..."> <soapenv:Body> <ns1:getBalanceResponse soapenv:encodingStyle="http://..." xmlns:ns1="http://bank.sample"> <getBalanceReturn xsi:type="xsd:string">1 Pedro pedro@hotmail.com 34.1</getBalanceReturn> </ns1:getBalanceResponse> </soapenv:Body> INTEL CONFIDENTIAL 35 1/3/2020

  34. SOAP Envelope – Fault element  The optional SOAP Fault element is used to hold error and status information for a SOAP message. Sub Description Description Found an invalid namespace for the SOAP Envelope element An immediate child element of the Header element, with the mustUnderstand attribute set to "1", was not understood The message was incorrectly formed or contained incorrect information There was a problem with the server so the message could not proceed Element <faultcode> <faultstring> <faultactor> <detail> FaultCode VersionMismatch A code for identifying the fault A human readable explanation of the fault Information about who caused the fault to happen Holds application specific error information related to the Body element MustUnderstand Client Server INTEL CONFIDENTIAL 36 1/3/2020

  35. WSDL  WSDL is an XML-based language for describing Web services and how to access them.  Stands for Web Services Description Language.  Used to describe and locate Web services. INTEL CONFIDENTIAL 37 1/3/2020

  36. Service contracts – WSDL files <?xml version="1.0" encoding="UTF-8"?> <wsdl:definitions ............ <wsdl:message name="getBalanceResponse"> <wsdl:part name="getBalanceReturn" type="xsd:string"/> </wsdl:message> <wsdl:message name="getBalanceRequest"> <wsdl:part name="accountId" type="xsd:int"/> </wsdl:message> <wsdl:portType name="BankService"> <wsdl:operation name="getBalance" parameterOrder="accountId"> <wsdl:input name="getBalanceRequest" message="impl:getBalanceRequest"/> <wsdl:output name="getBalanceResponse" message="impl:getBalanceResponse"/> </wsdl:operation> </wsdl:portType> <wsdl:binding name="BankServiceSoapBinding" type="impl:BankService"> <wsdlsoap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/> <wsdl:operation name="getBalance"> <wsdlsoap:operation soapAction=""/> <wsdl:input name="getBalanceRequest"> <wsdlsoap:body use="encoded" encodingStyle=... namespace="http://bank.sample"/> </wsdl:input> <wsdl:output name="getBalanceResponse"> <wsdlsoap:body use="encoded" encodingStyle=… namespace="http://bank.sample"/> </wsdl:output> </wsdl:operation> </wsdl:binding> <wsdl:service name="BankServiceService"> <wsdl:port name="BankService" binding="impl:BankServiceSoapBinding"> <wsdlsoap:address location="http://cbl-javoos:8082/BankWEB/services/BankService"/> </wsdl:port> </wsdl:service> </wsdl:definitions> INTEL CONFIDENTIAL 38 1/3/2020

  37. WSDL Contract Architecture INTEL CONFIDENTIAL 39 1/3/2020

  38. UDDI Registry  UDDI is a directory service where businesses can register and search for Web services.  Platform-independent framework for describing services, discovering businesses, and integrating business services by using the Internet.  Stands for Universal Description, Discovery and Integration.  Directory of web service interfaces described by WSDL  UDDI communicates via SOAP INTEL CONFIDENTIAL 40 1/3/2020

  39. UDDI Registry (cont’d)  Helps to find a web service and its description  Search by business  Search by service type  Two types of UDDI registries  Public registries  Private registries INTEL CONFIDENTIAL 41 1/3/2020

  40. Service Oriented Architecture The Details of SOA depends on your role… Business Architecture Implementation Architectural style which requires a service provider, requestor and a service description. or other portions of the organization. Programming model complete with standards, tools and technologies such as Web Services. Set of services that a business exposes to their customers and partners, Set of architectural principles, patterns and criteria which address characteristics such as modularity, encapsulation, loose coupling, separation of concerns, reuse, composability and single implementation. INTEL CONFIDENTIAL 42 1/3/2020

  41. SOA – WS relationship Web Services "Web services are software components described via WSDL which are capable of being accessed via standard network protocols such as SOAP over HTTP.“ • Web services achieves most of the goals of SOA. • Web Services technology is one style of creating services for SOA. BUT • SOA does not require the use of Web Services. • We can create useful services that don't speak SOAP. SOA and WS are not the same thing. INTEL CONFIDENTIAL 43 1/3/2020

  42. SOA – WS relationship Most of today's production Web Services systems are not service oriented architectures – they're simple remote procedure calls or point-to-point messaging via SOAP or well structured integration architectures. There are production service oriented architectures that do not primarily use Web Services - they use ftp, batch files, asynchronous messaging, etc. INTEL CONFIDENTIAL 44 1/3/2020

  43. Benefits of SOA  Support for all major vendors. WS Standards.  Interoperability and integration capability.  Services reuse. Well defined public interfaces.  High abstraction level.  User roles. Specialized profiles.  Easy assembling for new business process. INTEL CONFIDENTIAL 45 1/3/2020

  44. Limitations of SOA  Business components in closed application domains.  Performance issues in XML parsing.  Long-running asynchronous processes.  WS-Security implementation.  WS-Transaction overhead.  Complex data types interoperability. INTEL CONFIDENTIAL 46 1/3/2020

  45. Agenda  Web Services  Definition  Advantages and reservations  Classification: SOAP vs REST  SOAP-based WS  XML, XSL, XPath, XSLT  WSDL/ UDDI  SOAP  SOA (Service Oriented Architecture)  SOA Benefits  Demo: Creating and consuming a SOAP-based WS INTEL CONFIDENTIAL 47 1/3/2020

  46. Demo: Creating and consuming a SOAP-based WS INTEL CONFIDENTIAL 48 1/3/2020

  47. Agenda (cont’d)  RESTful WS  AJAX  The XmlHttpRequest object  The HttpRequest object  JSON  JSON data structures  JSON vs XML  Benefits and lowlights of JSON  Generating and Consuming JSON  Demo: JSON and REST-WS INTEL CONFIDENTIAL 49 1/3/2020

  48. Need for AJAX  Their ease of deployment allows a site to have millions of users with minimal cost  Traditional Web UI are not responsive to users  Websites forced users into submit/wait/redisplay  Ajax allows to build more dynamic and responsive Web applications  ability to communicate with the server asynchronously  use JS and DHTML to immediately update the UI  spawn an asynchronous request to the server to perform an update or query a database INTEL CONFIDENTIAL 50 1/3/2020

  49. AJAX  AJAX stands for Asynchronous JavaScript And XML  AJAX incorporates several technologies  Standards-based presentation using XHTML and CSS  Dynamic display and interaction using the Document Object Model  Asynchronous server communication using XMLHttpRequest  Supported by most modern browsers  Allows to perform HTTP requests which returns some form of response.  Can automatically parse an XML document sent in response to a request.  JavaScript binding everything together  AJAX allows to communicate with the web server to send and retrieve data without  loading a new page  reloading the current page INTEL CONFIDENTIAL 51 1/3/2020

  50. HTTP: Quick Overview  When loading http://www.example.net/index.html  The browser opens a connection to the host www.example.net  It then sends the server an HTTP request which consists of several lines of plain text  The server sends back an HTTP response which also consists of several lines of plain text INTEL CONFIDENTIAL 52 1/3/2020

More Related