Your SlideShare is downloading. ×
0
Web Services
Web Services
Web Services
Web Services
Web Services
Web Services
Web Services
Web Services
Web Services
Web Services
Web Services
Web Services
Web Services
Web Services
Web Services
Web Services
Web Services
Web Services
Web Services
Web Services
Web Services
Web Services
Web Services
Web Services
Web Services
Web Services
Web Services
Web Services
Web Services
Web Services
Web Services
Web Services
Web Services
Web Services
Web Services
Web Services
Web Services
Web Services
Web Services
Web Services
Web Services
Web Services
Web Services
Web Services
Web Services
Web Services
Web Services
Web Services
Web Services
Web Services
Web Services
Web Services
Web Services
Web Services
Web Services
Web Services
Web Services
Web Services
Web Services
Web Services
Web Services
Web Services
Web Services
Web Services
Web Services
Web Services
Web Services
Web Services
Web Services
Web Services
Web Services
Web Services
Web Services
Web Services
Web Services
Web Services
Web Services
Web Services
Web Services
Web Services
Web Services
Web Services
Web Services
Web Services
Web Services
Web Services
Web Services
Web Services
Web Services
Web Services
Web Services
Web Services
Web Services
Web Services
Web Services
Web Services
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Web Services

5,685

Published on

0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
5,685
On Slideshare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
220
Comments
0
Likes
2
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide
  • Web services and the service-oriented architecture ( SOA ) Understanding services The concept of services within an application has been around for a while. Services, much like components, are intended to be independent building blocks that collectively represent an application environment. Unlike traditional components, though, services have a number of unique characteristics that allow them to participate as part of a service-oriented architecture. One of these qualities is complete autonomy from other services. This means that each service is responsible for its own domain, which typically translates into limiting its scope to a specific business function (or a group of related functions). This design approach results in the creation of isolated units of business functionality loosely bound together by a common compliance to a standard communications framework. Due to the independence that services enjoy within this framework, the programming logic they encapsulate does not need to comply to any one platform or technology set. Web services have two types of uses. Reusable application components There are things different applications needs very often. So why make these over and over again? Web services can offer application components like currency conversion, weather reports or even language translation as services. Ideally, there will only be one type of each application component, and anyone can use it in their application. Connect existing software Web services help solve the interoperability problem by giving different applications a way to link their data. Using Web services you can exchange data between different applications and different platforms.
  • The syntax rules of XML are very simple and very strict. The rules are very easy to learn, and very easy to use. Because of this, creating software that can read and manipulate XML is very easy. The first line in the document - the XML declaration - defines the XML version and the character encoding used in the document. In this case the document conforms to the 1.0 specification of XML and uses the ISO-8859-1 (Latin-1/West European) character set. The next line describes the root element of the document (like it was saying: "this document is a note"): <note> The next 4 lines describe 4 child elements of the root (to, from, heading, and body): <to>Tove</to> <from>Jani</from> <heading>Reminder</heading> <body>Don't forget me this weekend!</body> And finally the last line defines the end of the root element:</note> Can you detect from this example that the XML document contains a Note to Tove from Jani? Don't you agree that XML is pretty self-descriptive? All XML elements must have an opening and a closing tag XML tags are case sensitive All XML elements must be properly nested All XML documents must have a root element (single) There is nothing special about XML There is nothing special about XML. It is just plain text with the addition of some tags enclosed in angle brackets. Software that can handle plain text can also handle XML. In a simple text editor, the XML tags will be visible and will not be handled specially. In an XML-aware application however, the XML tags can be handled specially. The tags may or may not be visible, or have a functional meaning, depending on the nature of the application. XML Elements are Extensible Let's imagine that we created an application that extracted the <to>, <from>, and <body> elements from the XML document to produce a given output. Imagine that the author of the XML document added some extra information to it: The application should still be able to find the <to>, <from>, and <body> elements in the XML document and produce the same output. “ XML documents are Extensible”. XML Elements have Relationships Elements are related as parents and children. Elements have Content Elements can have different content types. An XML element is everything from (including) the element's start tag to (including) the element's end tag. An element can have element content, mixed content, simple content, or empty content. An element can also have attributes . In the example above, book has element content , because it contains other elements. Chapter has mixed content because it contains both text and other elements. Para has simple content (or text content ) because it contains only text. Prod has empty content , because it carries no information. In the example above only the prod element has attributes . The attribute named id has the value "33-657". The attribute named media has the value "paper".  XML Elements have simple naming rules Names can contain letters, numbers, and other characters Names must not start with a number or punctuation character Names must not start with the letters xml (or XML, or Xml, etc) Names cannot contain spaces Elements have Content Elements can have different content types. An XML element is everything from (including) the element's start tag to (including) the element's end tag. An element can have element content, mixed content, simple content, or empty content. An element can also have attributes . In the example above, book has element content , because it contains other elements. Chapter has mixed content because it contains both text and other elements. Para has simple content (or text content ) because it contains only text. Prod has empty content , because it carries no information. In the example above only the prod element has attributes . The attribute named id has the value "33-657". The attribute named media has the value "paper". 
  • Attribute values must always be enclosed in quotes, but either single or double quotes can be used. For a person's sex, the person tag can be written like this: In the first example sex is an attribute. In the last, sex is a child element. Both examples provide the same information. There are no rules about when to use attributes, and when to use child elements. My experience is that attributes are handy in HTML, but in XML you should try to avoid them. Use child elements if the information feels like data. Should you avoid using attributes? Some of the problems with using attributes are: attributes cannot contain multiple values (child elements can) attributes are not easily expandable (for future changes) attributes cannot describe structures (child elements can) attributes are more difficult to manipulate by program code attribute values are not easy to test against a Document Type Definition (DTD) - which is used to define the legal elements of an XML document If you use attributes as containers for data, you end up with documents that are difficult to read and maintain. Try to use elements to describe data. Use attributes only to provide information that is not relevant to the data. Sometimes we assign ID references to elements. These ID references can be used to access XML elements in much the same way as the NAME or ID attributes in HTML. So a good way here is that metadata (data about data) should be stored as attributes, and that data itself should be stored as elements
  • A DTD defines the legal elements of an XML document. The purpose of a DTD is to define the legal building blocks of an XML document. It defines the document structure with a list of legal elements. XML Schema is an XML based alternative to DTD. W3C supports an alternative to DTD called XML Schema
  • It started with XSL and ended up with XSLT, XPath, and XSL-FO. CSS = HTML Style Sheets HTML uses predefined tags and the meaning of the tags are well understood. The <table> element in HTML defines a table - and a browser knows how to display it. Adding styles to HTML elements is simple. Telling a browser to display an element in a special font or color, is easy with CSS.  XSL = XML Style Sheets XML does not use predefined tags (we can use any tag-names we like), and the meaning of these tags are not well understood . A <table> element could mean an HTML table, a piece of furniture, or something else - and a browser does not know how to display it . XSL describes how the XML document should be displayed! XSL - More Than a Style Sheet Language XSL consists of three parts: XSLT - a language for transforming XML documents XPath - a language for navigating in XML documents XSL-FO - a language for formatting XML documents Due XSLT uses xPath to navigate the XML document, we should start by xPath introduction first
  • XPath is a language for finding information in an XML document. XPath is used to navigate through elements and attributes in an XML document. XPath Path Expressions XPath uses path expressions to select nodes or node-sets in an XML document. These path expressions look very much like the expressions you see when you work with a traditional computer file system. XPath Standard Functions XPath includes over 100 built-in functions. There are functions for string values, numeric values, date and time comparison, node and QName manipulation, sequence manipulation, Boolean values, and more. XPath is Used in XSLT XPath is a major element in the XSLT standard. Without XPath knowledge you will not be able to create XSLT documents. XQuery and XPointer are both built on XPath expressions. XQuery 1.0 and XPath 2.0 share the same data model and support the same functions and operators. XPath is a W3C Standard XPath became a W3C Recommendation 16. November 1999. XPath was designed to be used by XSLT, XPointer and other XML parsing software
  • Nodes In XPath, there are seven kinds of nodes: element, attribute, text, namespace, processing-instruction, comment, and document (root) nodes. XML documents are treated as trees of nodes. The root of the tree is called the document node (or root node). Example: <bookstore> (document node) <author>J K. Rowling</author> (element node) lang="en" (attribute node) Atomic values Atomic values are nodes with no children or parent. Example of atomic values: J K. Rowling"en" Items Items are atomic values or nodes. Relationship of Nodes Parent Each element and attribute has one parent. In the example; the book element is the parent of the title, author, year, and price. Children Element nodes may have zero, one or more children. In the example; the title, author, year, and price elements are all children of the book element. Siblings Nodes that have the same parent Ancestors A node's parent, parent's parent, etc. Descendants A node's children, children's children, etc.
  • XPath uses path expressions to select nodes or node-sets in an XML document. The node is selected by following a path or steps. Selecting Nodes XPath uses path expressions to select nodes in an XML document. The node is selected by following a path or steps. The most useful path expressions are listed below: In the table below we have listed some path expressions and the result of the expressions: Path ExpressionResult /bookstore/* Selects all the child nodes of the bookstore element //* Selects all elements in the document //title[@*] Selects all title elements which have any attribute
  • XSLT is a language for transforming XML documents into XHTML documents or to other XML documents. XSLT = XSL Transformations XSLT is the most important part of XSL. XSLT is used to transform an XML document into another XML document, or another type of document that is recognized by a browser, like HTML and XHTML. Normally XSLT does this by transforming each XML element into an (X)HTML element. With XSLT you can add/remove elements and attributes to or from the output file. You can also rearrange and sort elements, perform tests and make decisions about which elements to hide and display, and a lot more. A common way to describe the transformation process is to say that XSLT transforms an XML source-tree into an XML result-tree. XSLT Uses XPath XSLT uses XPath to find information in an XML document. XPath is used to navigate through elements and attributes in XML documents. How Does it Work? In the transformation process, XSLT uses XPath to define parts of the source document that should match one or more predefined templates. When a match is found, XSLT will transform the matching part of the source document into the result document.
  • Start with a Raw XML Document We want to transform the following XML document ("cdcatalog.xml") into XHTML: Create an XSL Style Sheet Then you create an XSL Style Sheet ("cdcatalog.xsl") with a transformation template: Since an XSL style sheet is an XML document itself, it always begins with the XML declaration: <?xml version="1.0" encoding="ISO-8859-1"?> . The next element, <xsl:stylesheet> , defines that this document is an XSLT style sheet document (along with the version number and XSLT namespace attributes). The <xsl:template> element defines a template. The match="/" attribute associates the template with the root of the XML source document. The content inside the <xsl:template> element defines some HTML to write to the output. The last two lines defines the end of the template and the end of the style sheet.
  • XML Web services The most widely accepted and successful type of service is the XML Web service (from hereon referred to as Web service or, simply, service ). This type of service has two fundamental requirements: it communicates via Internet protocols (most commonly HTTP) it sends and receives data formatted as XML documents That's pretty much it. You can write a simple ASP or JSP script that resides on a Web server sending and receiving XML formatted messages via HTTP, and you can go out and get yourself an "I'm Service-Oriented" T-shirt. Broad acceptance of the Web service design model has resulted in the emergence of a set of supplementary technologies that have become de facto standards. An industry standard Web service, therefore, generally is expected to: provide a service description that, at minimum, consists of a WSDL document be capable of transporting XML documents using SOAP over HTTP These technologies do not alter the core functionality of a Web service as much as they do its ability to represent itself and communicate in a standard way. Many of the architectural conventions expressed in this chapter assume that SOAP and WSDL are part of the described Web services framework. Additionally, it is common for Web services to: be able to act as both the requestor and provider of a service be registered with a discovery agent through which they can be located In a typical conversation with a Web service, the client initiating the request is a Web service as well. Any interface exposed by this "client service" also qualifies it as a service from which other services can request information. Therefore, Web services do not fit into the classic client-server model. Instead, they tend to establish a peer-to-peer system, where each service can play the role of client or server.
  • WSDL Describes Web Services WSDL stands for Web Services Description Language. WSDL is a document written in XML. The document describes a Web service. It specifies the location of the service and the operations (or methods) the service exposes.
  • Implementation - Interoperability Problems
  • The first line contains the HTTP verb or method. In this case, the method is GET which means return the following document. Following that is the path to the document to retrieve (/about/index.html). The HTTP/1.1 tells the server what version of HTTP the browser supports. The lines that follow are called request headers. The specify additional information that may be used by the web server to help it send a proper response to the browser.
  • The first line contains the HTTP version and a three digit status code. The text following that number is a short description of that code. 200 means "OK," the request was successfully processed. If the requested page did not exist, the status would be "404 Not found." The lines following are request headers. Like the response headers, these give additional information about the response such as the document type ("text/html") and size (534 bytes). A blank line follows, signaling the end of the response header. The rest of the lines represent the response data. In this case, it is the HTML of the page which the browser will parse and render.
  • Transcript

    • 1. SOAP-based and RESTful Web Services Claudio Ochoa, PhD Sr Software Engineer @ Intel SEG – UNSL September 2007
    • 2. Agenda <ul><li>Web Services </li></ul><ul><ul><li>Definition </li></ul></ul><ul><ul><li>Advantages and reservations </li></ul></ul><ul><ul><li>Classification: SOAP vs REST </li></ul></ul><ul><li>SOAP-based WS </li></ul><ul><ul><li>XML, XSL, XPath, XSLT </li></ul></ul><ul><ul><li>WSDL/ UDDI </li></ul></ul><ul><ul><li>SOAP </li></ul></ul><ul><ul><li>SOA (Service Oriented Architecture) </li></ul></ul><ul><ul><ul><li>SOA Benefits </li></ul></ul></ul><ul><ul><li>Demo: Creating and consuming a SOAP-based WS </li></ul></ul>
    • 3. Agenda (cont’d) <ul><li>RESTful WS </li></ul><ul><ul><li>AJAX </li></ul></ul><ul><ul><ul><li>The XmlHttpRequest object </li></ul></ul></ul><ul><ul><ul><li>The HttpRequest object </li></ul></ul></ul><ul><ul><li>JSON </li></ul></ul><ul><ul><ul><li>JSON data structures </li></ul></ul></ul><ul><ul><ul><li>JSON vs XML </li></ul></ul></ul><ul><ul><ul><li>Benefits and lowlights of JSON </li></ul></ul></ul><ul><ul><ul><li>Generating and Consuming JSON </li></ul></ul></ul><ul><ul><li>Demo: JSON and REST-WS </li></ul></ul>
    • 4. Agenda (cont’d) <ul><li>Mashups </li></ul><ul><ul><li>Example of mashups </li></ul></ul><ul><ul><li>Mashing up a yahoo map object </li></ul></ul><ul><li>Hands On </li></ul><ul><ul><li>Consuming a REST-WS </li></ul></ul><ul><ul><li>Creating/Adding a mashup </li></ul></ul><ul><li>Wrap up </li></ul>
    • 5. Agenda <ul><li>Web Services </li></ul><ul><ul><li>Definition </li></ul></ul><ul><ul><li>Advantages and reservations </li></ul></ul><ul><ul><li>Classification: SOAP vs REST </li></ul></ul><ul><li>SOAP-based WS </li></ul><ul><ul><li>XML, XSL, XPath, XSLT </li></ul></ul><ul><ul><li>WSDL/ UDDI </li></ul></ul><ul><ul><li>SOAP </li></ul></ul><ul><ul><li>SOA (Service Oriented Architecture) </li></ul></ul><ul><ul><ul><li>SOA Benefits </li></ul></ul></ul><ul><ul><li>Demo: Creating and consuming a SOAP-based WS </li></ul></ul>
    • 6. Need for Web Services <ul><li>Distributed Computing allows sharing information and processing </li></ul><ul><li>Traditional distributed processing models assume </li></ul><ul><ul><li>Common environment or architecture (J2EE, COM+) </li></ul></ul><ul><ul><li>Interoperability is easier to achieve </li></ul></ul><ul><li>Distributed processing using different platforms, architectures, and dev languages is complicated </li></ul><ul><ul><li>Interoperability between different systems is key </li></ul></ul><ul><ul><li>WS are an approach for dealing with this problem </li></ul></ul>
    • 7. Web Services <ul><li>WS provide a way to access biz or app logic using Internet standard protocols (e.g. HTTP, SMTP, FTP) </li></ul><ul><ul><li>Organizations already have communication SW and infrastructure needed to support WS </li></ul></ul><ul><li>What are WS for? </li></ul><ul><ul><li>Early Internet apps (mail, web sites) helped individuals communicate with each other </li></ul></ul><ul><ul><li>WS help applications communicate with each other </li></ul></ul><ul><li>WS allow interoperability across independent processing environments and domains </li></ul>
    • 8. WS: advantages <ul><li>Interaction between different companies systems </li></ul><ul><li>Interoperation between apps inside a company </li></ul><ul><li>Processing is loosely coupled </li></ul><ul><ul><li>No need for common application environment </li></ul></ul><ul><li>Do not abandon existing investments in software </li></ul><ul><ul><li>Add WS front end to existing apps </li></ul></ul><ul><li>Big players (Microsoft, IBM, Sun) are investing in WS and creating tools to support them </li></ul>
    • 9. WS: reservations <ul><li>WS are not proven technology </li></ul><ul><ul><li>Fashionable solution of the day? </li></ul></ul><ul><li>SOAP WS rely on XML </li></ul><ul><ul><li>XML expands the size of data several times over </li></ul></ul><ul><ul><li>More processing is needed to format and parse msgs </li></ul></ul><ul><li>Internal apps are now exposed to external threats </li></ul><ul><ul><li>WS can expose valuable corporate data, apps, systems… </li></ul></ul>
    • 10. WS: Classification <ul><li>WS can be classified in two main kinds </li></ul><ul><ul><li>SOAP-based WS </li></ul></ul><ul><ul><li>RESTful WS </li></ul></ul><ul><li>SOAP-based WS have been around for a while </li></ul><ul><ul><li>Google (except blogger), enterprise software </li></ul></ul><ul><li>RESTful WS are the trendy way for designing WS </li></ul><ul><ul><li>Yahoo, Flickr, del.icio.us, pubsub, bloglines, technorati </li></ul></ul><ul><ul><li>eBay and Amazon use both REST and SOAP </li></ul></ul>
    • 11. SOAP-based WS: overview <ul><li>SOAP is a protocol for exchanging XML-based messages over computer networks </li></ul><ul><li>SOAP stands for SOAP </li></ul><ul><ul><li>Originally stood for Simple Object Access Protocol </li></ul></ul><ul><ul><li>Later stood for Service Oriented Architecture Protocol </li></ul></ul><ul><li>Provides a basic messaging framework </li></ul><ul><ul><li>Successor of XML-RPC (still used for some apps like blogger) </li></ul></ul><ul><ul><li>Makes use of Internet transport protocol (HTTP/SMTP) </li></ul></ul>
    • 12. SOAP-based WS (cont’d) Internet Protocols XML Web services HTTP SMTP FTP SOAP UDDI WSDL Web Services building blocks
    • 13. Advantages of SOAP WS <ul><li>Easier communication behind proxies and firewalls than previous remote execution technology. </li></ul><ul><li>Versatile - allows the use of different transport protocols. </li></ul><ul><li>Easy to consume (sometimes) </li></ul><ul><li>Rigid - type checking, adheres to a contract </li></ul><ul><li>Development tools </li></ul>
    • 14. RESTful WS <ul><li>REST stands for Representational State Transfer </li></ul><ul><li>Collection of network architecture principles that outline how resources are defined and addressed </li></ul><ul><ul><li>All resources can be uniquely identified by an URI </li></ul></ul><ul><ul><li>No need for additional message layer like SOAP </li></ul></ul><ul><li>An application interacts with a resource by knowing </li></ul><ul><ul><li>the identifier of the resource </li></ul></ul><ul><ul><li>the action required </li></ul></ul><ul><li>No need to know if there are caches, proxies, gateways, firewalls, tunnels between client and server... </li></ul><ul><li>The application needs to understand the format of the information ( representation ) returned, </li></ul><ul><ul><li>HTML, XML, JSON, images… </li></ul></ul>
    • 15. Advantages of Restful WS <ul><li>Lightweight - not a lot of extra xml markup </li></ul><ul><ul><li>Human Readable Results </li></ul></ul><ul><li>Improved response times and server loading characteristics </li></ul><ul><li>Improves server scalability by reducing the need to maintain communication state. </li></ul><ul><ul><li>different servers can be used to handle initial and subsequent requests </li></ul></ul><ul><li>A single browser can access any any resource </li></ul><ul><ul><li>Easy to build, no toolkits required </li></ul></ul><ul><li>Does not require a separate resource discovery mechanism </li></ul>
    • 16. Agenda <ul><li>Web Services </li></ul><ul><ul><li>Definition </li></ul></ul><ul><ul><li>Advantages and reservations </li></ul></ul><ul><ul><li>Classification: SOAP vs REST </li></ul></ul><ul><li>SOAP-based WS </li></ul><ul><ul><li>XML, XSL, XPath, XSLT </li></ul></ul><ul><ul><li>WSDL/ UDDI </li></ul></ul><ul><ul><li>SOAP </li></ul></ul><ul><ul><li>SOA (Service Oriented Architecture) </li></ul></ul><ul><ul><ul><li>SOA Benefits </li></ul></ul></ul><ul><ul><li>Demo: Creating and consuming a SOAP-based WS </li></ul></ul>
    • 17. SOAP-based Web Services <ul><li>Web services are application components </li></ul><ul><li>Web services communicate using open protocols </li></ul><ul><li>Web services are self-contained and self-describing </li></ul><ul><li>Web services can be discovered using UDDI </li></ul><ul><li>Web services can be used by other applications ( Interoperability ) </li></ul><ul><li>XML is the basis for SOAP-Web services </li></ul>
    • 18. XML Overview <ul><li>XML stands for eXtensible Markup Language . </li></ul><ul><li>XML is a markup language much like HTML. </li></ul><ul><li>XML tags are not predefined . </li></ul><ul><li>XML uses a Document Type Definition ( DTD ) or an XML Schema to describe the data. </li></ul><ul><li>XML with a DTD is designed to be self-descriptive . </li></ul><ul><li>XML was designed to store , carry , describe and exchange data. </li></ul>
    • 19. XML elements <ul><li>Begin with a start tag and end with an end tag </li></ul><ul><li>Unlike html, every start tag must have a matching end tag </li></ul><ul><li>XML elements can be nested </li></ul><ul><ul><ul><ul><li><book> </li></ul></ul></ul></ul><ul><ul><ul><ul><li><title> Web Services </title> </li></ul></ul></ul></ul><ul><ul><ul><ul><li><author> </li></ul></ul></ul></ul><ul><ul><ul><ul><li><firstname>John</firstname> </li></ul></ul></ul></ul><ul><ul><ul><ul><li><lastname> Doe </lastname> </li></ul></ul></ul></ul><ul><ul><ul><ul><li></author> </li></ul></ul></ul></ul><ul><ul><ul><ul><li><isbn> 0-471-26716-5 </isbn> </li></ul></ul></ul></ul><ul><ul><ul><ul><li></book> </li></ul></ul></ul></ul><price> 123.45 </price>
    • 20. XML Syntax <ul><li>XML documents use a self-describing and simple syntax. </li></ul><ul><ul><li><?xml version=&quot;1.0&quot; encoding=&quot;ISO-8859-1&quot;?> <note> <to>Juan</to> <from>Pedro</from> <heading>Reminder</heading> <body>Don't forget me this weekend!</body> </note> </li></ul></ul><ul><li>XML elements are extensible . </li></ul><ul><ul><ul><li><note> </li></ul></ul></ul><ul><ul><ul><li><date>2002-08-01</date> </li></ul></ul></ul><ul><ul><ul><li><to>Juan</to> </li></ul></ul></ul><ul><ul><ul><li><from>Pedro</from> </li></ul></ul></ul><ul><ul><ul><li><heading>Reminder</heading> </li></ul></ul></ul><ul><ul><ul><li><body>Don't forget me this weekend!</body> </li></ul></ul></ul><ul><ul><ul><li></note> </li></ul></ul></ul>
    • 21. XML Attributes <ul><li>XML elements can have attributes . </li></ul><ul><ul><li>Attributes are used to provide additional information about elements. </li></ul></ul><ul><li>Data can be stored in child elements or in attributes . </li></ul><ul><ul><li><person sex=&quot;female&quot; > <firstname>Anna</firstname> <lastname>Smith</lastname> </person> </li></ul></ul><ul><ul><li><person> <sex>female</sex> <firstname>Anna</firstname> <lastname>Smith</lastname> </person> </li></ul></ul>
    • 22. XML Validation Well Formed vs Valid XML <ul><li>A Well Formed XML document has correct XML syntax . </li></ul><ul><li><?xml version=&quot;1.0&quot; encoding=&quot;ISO-8859-1&quot;?> <note> <to>Tove</to> <from>Jani</from> <heading>Reminder</heading> <body>Don't forget me this weekend!</body> </note> </li></ul><ul><li>A Valid XML document also conforms to a DTD . </li></ul><ul><li><?xml version=&quot;1.0&quot; encoding=&quot;ISO-8859-1&quot;?> <!DOCTYPE note SYSTEM &quot; InternalNote.dtd &quot;> <note> <to>Tove</to> <from>Jani</from> <heading>Reminder</heading> <body>Don't forget me this weekend!</body> </note> </li></ul>
    • 23. XML – Other basic concepts <ul><li>XML Namespaces </li></ul><ul><ul><li>Provide a method to avoid element name conflicts . </li></ul></ul><ul><li>XML Encoding : </li></ul><ul><ul><li>Allow representing extended or foreign characters </li></ul></ul><ul><li>XML Parsers : </li></ul><ul><ul><li>Provide a way to create and manipulate an XML document. </li></ul></ul><ul><li>XML CDATA : </li></ul><ul><ul><li>Provide a way to store text data which is ignored by the parser. </li></ul></ul>
    • 24. URIs <ul><li>URIs identify abstract or physical resources </li></ul><ul><li>A URI follows the form <scheme>:<scheme-specific-part> </li></ul><ul><li>The most familiar form of a URI is the URL </li></ul><ul><ul><li>It denotes location and protocol to access a resource </li></ul></ul>
    • 25. XSL languages <ul><li>XSL stands for E X tensible S tylesheet L anguage </li></ul><ul><ul><li>CSS = HTML Style Sheets </li></ul></ul><ul><ul><li>XSL = XML Style Sheets </li></ul></ul><ul><li>XSL started as a way to describe how XML data should be displayed, but rapidly evolved to 3 main languages: </li></ul><ul><ul><li>XSLT - a language for transforming XML documents </li></ul></ul><ul><ul><li>XPath - a language for navigating in XML documents </li></ul></ul><ul><ul><li>XSL-FO - a language for formatting XML documents </li></ul></ul>
    • 26. XPath <ul><li>Language for finding information in an XML document. </li></ul><ul><ul><li>Is used to navigate through elements and attributes in an XML document. </li></ul></ul><ul><li>Syntax for defining parts of an XML document. </li></ul><ul><li>Library of standard functions. </li></ul><ul><li>W3C Standard. </li></ul>
    • 27. XPath Nodes <ul><li>In XPath, XML documents are treated as trees of nodes. There are seven types of nodes: </li></ul><ul><ul><li>Document (root) </li></ul></ul><ul><ul><li>Element </li></ul></ul><ul><ul><li>Attribute </li></ul></ul><ul><ul><li>Text </li></ul></ul><ul><ul><li>Namespace </li></ul></ul><ul><ul><li>Processing-instruction </li></ul></ul><ul><ul><li>Comment </li></ul></ul><ul><ul><li><?xml version=&quot;1.0&quot; encoding=&quot;ISO-8859-1&quot;?> <bookstore> <book> <title lang=&quot;en&quot;>Harry Potter</title> <author>J K. Rowling</author> <year>2005</year> <price>29.99</price> </book> </bookstore </li></ul></ul>
    • 28. XPath Syntax <ul><li>XPath uses path expressions to select nodes or node-sets in an XML document. </li></ul><ul><li>XPath wildcards can be used to select unknown XML elements. </li></ul>Matches any node of any kind node() Matches any attribute node @* Matches any element node * Description Wildcard Selects all title elements which have any attribute //title[@*] Selects all elements in the document //* Selects all the child nodes of the bookstore element /bookstore/* Result Path Expression
    • 29. XSLT basics <ul><li>XSLT is a language for transforming XML docs into XHTML documents or to other XML documents. </li></ul><ul><li>XSLT stands for XSL Transformations </li></ul><ul><li>XSLT is the most important part of XSL </li></ul><ul><li>XSLT uses XPath to navigate in XML documents </li></ul><ul><li>XSLT is a W3C Recommendation </li></ul>
    • 30. XSLT – Transformation example <?xml version=&quot;1.0&quot; encoding=&quot;ISO-8859-1&quot;?> <catalog> <cd> <title>Empire Burlesque</title> <artist>Bob Dylan</artist> <country>USA</country> <company>Columbia</company> <price>10.90</price> <year>1985</year> </cd> . . . </catalog> <?xml version=&quot;1.0&quot; encoding=&quot;ISO-8859-1&quot;?> <xsl:stylesheet version=&quot;1.0&quot; xmlns:xsl=&quot;http://www.w3.org/1999/XSL/Transform&quot;> <xsl:template match=&quot;/&quot;> <html> <body> <h2>My CD Collection</h2> <table border=&quot;1&quot;> <tr bgcolor=&quot;#9acd32&quot;> <th align=&quot;left&quot;>Title</th> <th align=&quot;left&quot;>Artist</th> </tr> <xsl:for-each select=&quot;catalog/cd&quot;> <tr> <td><xsl:value-of select=&quot;title&quot;/></td> <td><xsl:value-of select=&quot;artist&quot;/></td> </tr> </xsl:for-each> </table> </body> </html> </xsl:template> </xsl:stylesheet>>
    • 31. Web Services Operations Service Provider Service Requestor Service Registry find bind publish Requestors query registry to discover a set of services that it can interact with Providers advertise their services to service registry Requestors negotiate with providers to access and invoke services
    • 32. XML Web Services Framework
    • 33. <ul><li>SOAP is a simple XML based protocol to let applications exchange information over HTTP. </li></ul><ul><ul><li>Stands for Simple Object Access Protocol . </li></ul></ul><ul><ul><li>Protocol for accessing a Web Service . </li></ul></ul><ul><ul><li>Platform and language independent . </li></ul></ul><ul><ul><li>Allows you to get around firewalls . </li></ul></ul><ul><li>A SOAP message MUST be encoded using XML </li></ul><ul><li>A SOAP message MUST use the SOAP Envelope namespace </li></ul><ul><li>A SOAP message MUST use the SOAP Encoding namespace </li></ul><ul><li>A SOAP message must NOT contain a DTD reference </li></ul><ul><li>A SOAP message must NOT contain XML Processing Instructions </li></ul>SOAP < soap:Envelope xmlns:soap=&quot;http://www.w3.org/2001/12/soap-envelope&quot; soap:encodingStyle=&quot;http://www.w3.org/2001/12/soap-encoding&quot;> < soap:Header > ... ... </ soap:Header > < soap:Body > ... ... < soap:Fault > ... ... </ soap:Fault > </ soap:Body > </ soap:Envelope >
    • 34. SOAP Envelope – Header element <ul><li>The optional SOAP Header element contains application specific information (like authentication, payment, etc) about the SOAP message. </li></ul><ul><li>If the Header element is present, it must be the first child element of the Envelope element. </li></ul>
    • 35. SOAP Envelope – Body element <ul><li>The required SOAP Body element contains the actual SOAP message intended for the ultimate endpoint of the message. </li></ul><ul><li>SOAP Request Envelope </li></ul><ul><li>SOAP Response Envelope </li></ul><?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; ?> <soapenv:Envelope xmlns:xsd=&quot; http://.... &quot;xmlns:soapenv= http://.... xmlns:xsi=&quot; http://... &quot;> <soapenv:Body> <ns0:getBalance xmlns:ns0=&quot; http://bank.sample “ soapenv:encodingStyle=&quot; http://... &quot;> <accountId xsi:type=&quot; xsd:int &quot;> 1 </accountId> </ns0:getBalance> </soapenv:Body> </soapenv:Envelope> <soapenv:Envelope xmlns:soapenv=&quot; http://... &quot; xmlns:xsd=&quot; http://... &quot; xmlns:xsi=&quot; http://... &quot;> <soapenv:Body> <ns1:getBalanceResponse soapenv:encodingStyle=&quot; http://... &quot; xmlns:ns1=&quot; http://bank.sample &quot;> <getBalanceReturn xsi:type=&quot; xsd:string &quot;> 1 Pedro pedro@hotmail.com 34.1 </getBalanceReturn> </ns1:getBalanceResponse> </soapenv:Body> </soapenv:Envelope>
    • 36. SOAP Envelope – Fault element <ul><li>The optional SOAP Fault element is used to hold error and status information for a SOAP message. </li></ul>Holds application specific error information related to the Body element <detail> Information about who caused the fault to happen <faultactor> A human readable explanation of the fault <faultstring> A code for identifying the fault <faultcode> Description Sub Element There was a problem with the server so the message could not proceed Server The message was incorrectly formed or contained incorrect information Client An immediate child element of the Header element, with the mustUnderstand attribute set to &quot;1&quot;, was not understood MustUnderstand Found an invalid namespace for the SOAP Envelope element VersionMismatch Description FaultCode
    • 37. WSDL <ul><li>WSDL is an XML-based language for describing Web services and how to access them. </li></ul><ul><ul><li>Stands for Web Services Description Language. </li></ul></ul><ul><ul><li>Used to describe and locate Web services. </li></ul></ul>
    • 38. Service contracts – WSDL files <?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?> <wsdl:definitions ............ < wsdl:message name=&quot;getBalanceResponse&quot;> < wsdl:part name=&quot;getBalanceReturn&quot; type =&quot;xsd:string&quot;/> </ wsdl:message > <wsdl:message name=&quot;getBalanceRequest&quot;> <wsdl:part name=&quot;accountId&quot; type =&quot;xsd:int&quot;/> </wsdl:message> < wsdl:portType name=&quot;BankService&quot;> < wsdl:operation name=&quot;getBalance&quot; parameterOrder=&quot;accountId&quot;> <wsdl:input name=&quot;getBalanceRequest&quot; message=&quot;impl:getBalanceRequest&quot;/> <wsdl:output name=&quot;getBalanceResponse&quot; message=&quot;impl:getBalanceResponse&quot;/> </ wsdl:operation > </ wsdl:portType > < wsdl:binding name=&quot;BankServiceSoapBinding&quot; type=&quot;impl:BankService&quot;> <wsdlsoap:binding style=&quot;rpc&quot; transport=&quot;http://schemas.xmlsoap.org/soap/http&quot;/> <wsdl:operation name=&quot;getBalance&quot;> <wsdlsoap:operation soapAction=&quot;&quot;/> <wsdl:input name=&quot;getBalanceRequest&quot;> <wsdlsoap:body use=&quot;encoded&quot; encodingStyle=... namespace=&quot;http://bank.sample&quot;/> </wsdl:input> <wsdl:output name=&quot;getBalanceResponse&quot;> <wsdlsoap:body use=&quot;encoded&quot; encodingStyle=… namespace=&quot;http://bank.sample&quot;/> </wsdl:output> </wsdl:operation> </ wsdl:binding > < wsdl:service name=&quot;BankServiceService&quot;> < wsdl:port name=&quot;BankService&quot; binding=&quot;impl:BankServiceSoapBinding&quot;> <wsdlsoap:address location=&quot;http://cbl-javoos:8082/BankWEB/services/BankService&quot;/> </ wsdl:port > </ wsdl:service > </wsdl:definitions>
    • 39. WSDL Contract Architecture
    • 40. UDDI Registry <ul><li>UDDI is a directory service where businesses can register and search for Web services. </li></ul><ul><ul><li>Platform-independent framework for describing services, discovering businesses, and integrating business services by using the Internet. </li></ul></ul><ul><ul><li>Stands for Universal Description, Discovery and Integration. </li></ul></ul><ul><ul><li>Directory of web service interfaces described by WSDL </li></ul></ul><ul><ul><li>UDDI communicates via SOAP </li></ul></ul>
    • 41. UDDI Registry (cont’d) <ul><li>Helps to find a web service and its description </li></ul><ul><ul><li>Search by business </li></ul></ul><ul><ul><li>Search by service type </li></ul></ul><ul><li>Two types of UDDI registries </li></ul><ul><ul><li>Public registries </li></ul></ul><ul><ul><li>Private registries </li></ul></ul>
    • 42. Service Oriented Architecture Business Architecture Implementation Programming model complete with standards, tools and technologies such as Web Services. Architectural style which requires a service provider, requestor and a service description. Set of architectural principles, patterns and criteria which address characteristics such as modularity, encapsulation, loose coupling, separation of concerns, reuse, composability and single implementation. Set of services that a business exposes to their customers and partners, or other portions of the organization. The Details of SOA depends on your role…
    • 43. SOA – WS relationship Web Services &quot;Web services are software components described via WSDL which are capable of being accessed via standard network protocols such as SOAP over HTTP.“ <ul><li>Web services achieves most of the goals of SOA. </li></ul><ul><li>Web Services technology is one style of creating services for SOA. </li></ul><ul><li>SOA does not require the use of Web Services. </li></ul><ul><li>We can create useful services that don't speak SOAP . </li></ul>SOA and WS are not the same thing. BUT
    • 44. 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.
    • 45. Benefits of SOA <ul><li>Support for all major vendors. WS Standards. </li></ul><ul><li>Interoperability and integration capability. </li></ul><ul><li>Services reuse . Well defined public interfaces. </li></ul><ul><li>High abstraction level. </li></ul><ul><li>User roles . Specialized profiles. </li></ul><ul><li>Easy assembling for new business process. </li></ul>
    • 46. Limitations of SOA <ul><li>Business components in closed application domains. </li></ul><ul><li>Performance issues in XML parsing. </li></ul><ul><li>Long-running asynchronous processes. </li></ul><ul><li>WS-Security implementation. </li></ul><ul><li>WS-Transaction overhead . </li></ul><ul><li>Complex data types interoperability. </li></ul>
    • 47. Agenda <ul><li>Web Services </li></ul><ul><ul><li>Definition </li></ul></ul><ul><ul><li>Advantages and reservations </li></ul></ul><ul><ul><li>Classification: SOAP vs REST </li></ul></ul><ul><li>SOAP-based WS </li></ul><ul><ul><li>XML, XSL, XPath, XSLT </li></ul></ul><ul><ul><li>WSDL/ UDDI </li></ul></ul><ul><ul><li>SOAP </li></ul></ul><ul><ul><li>SOA (Service Oriented Architecture) </li></ul></ul><ul><ul><ul><li>SOA Benefits </li></ul></ul></ul><ul><ul><li>Demo: Creating and consuming a SOAP-based WS </li></ul></ul>
    • 48. Demo: Creating and consuming a SOAP-based WS
    • 49. Agenda (cont’d) <ul><li>RESTful WS </li></ul><ul><ul><li>AJAX </li></ul></ul><ul><ul><ul><li>The XmlHttpRequest object </li></ul></ul></ul><ul><ul><ul><li>The HttpRequest object </li></ul></ul></ul><ul><ul><li>JSON </li></ul></ul><ul><ul><ul><li>JSON data structures </li></ul></ul></ul><ul><ul><ul><li>JSON vs XML </li></ul></ul></ul><ul><ul><ul><li>Benefits and lowlights of JSON </li></ul></ul></ul><ul><ul><ul><li>Generating and Consuming JSON </li></ul></ul></ul><ul><ul><li>Demo: JSON and REST-WS </li></ul></ul>
    • 50. Need for AJAX <ul><li>Their ease of deployment allows a site to have millions of users with minimal cost </li></ul><ul><li>Traditional Web UI are not responsive to users </li></ul><ul><ul><li>Websites forced users into submit/wait/redisplay </li></ul></ul><ul><li>Ajax allows to build more dynamic and responsive Web applications </li></ul><ul><ul><li>ability to communicate with the server asynchronously </li></ul></ul><ul><ul><li>use JS and DHTML to immediately update the UI </li></ul></ul><ul><ul><li>spawn an asynchronous request to the server to perform an update or query a database </li></ul></ul>
    • 51. AJAX <ul><li>AJAX stands for Asynchronous JavaScript And XML </li></ul><ul><li>AJAX incorporates several technologies </li></ul><ul><ul><li>Standards-based presentation using XHTML and CSS </li></ul></ul><ul><ul><li>Dynamic display and interaction using the Document Object Model </li></ul></ul><ul><ul><li>Asynchronous server communication using XMLHttpRequest </li></ul></ul><ul><ul><ul><li>Supported by most modern browsers </li></ul></ul></ul><ul><ul><ul><li>Allows to perform HTTP requests which returns some form of response. </li></ul></ul></ul><ul><ul><ul><li>Can automatically parse an XML document sent in response to a request. </li></ul></ul></ul><ul><ul><li>JavaScript binding everything together </li></ul></ul><ul><li>AJAX allows to communicate with the web server to send and retrieve data without </li></ul><ul><ul><li>loading a new page </li></ul></ul><ul><ul><li>reloading the current page </li></ul></ul>
    • 52. HTTP: Quick Overview <ul><li>When loading http://www.example.net/index.html </li></ul><ul><ul><li>The browser opens a connection to the host www.example.net </li></ul></ul><ul><ul><li>It then sends the server an HTTP request which consists of several lines of plain text </li></ul></ul><ul><ul><li>The server sends back an HTTP response which also consists of several lines of plain text </li></ul></ul>
    • 53. HTTP Request <ul><li>Contains </li></ul><ul><ul><li>HTTP method </li></ul></ul><ul><ul><li>Path to document to retrieve </li></ul></ul><ul><ul><li>HTTP version </li></ul></ul><ul><ul><li>Request header </li></ul></ul>GET /index.html HTTP/1.1 Host: www.example.net User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.12)... Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,... Accept-Language: en-us,en;q=0.5 Accept-Encoding: gzip,deflate Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7 Keep-Alive: 300 Proxy-Connection: keep-alive Pragma: no-cache Cache-Control: no-cache
    • 54. HTTP Response <ul><li>The web server will return a response </li></ul><ul><li>The response consists of several lines of plain text. </li></ul>HTTP/1.x 200 OK Server: Microsoft-IIS/5.1 Date: Fri, 20 Jan 2006 19:29:47 GMT Content-Length: 534 Content-Type: text/html Cache-Control: private <html> <head> <title>About Us</title> </head> <body> <h1>About us</h1> <p>...</p> </body> </html> Response Data Response Header HTTP version and status
    • 55. Passing Data in an HTTP Request <ul><li>Append a query string to the URL </li></ul><ul><ul><li>http://www.example.net/signup.asp? name=Jane+Doe&email=jane%40myhost.com </li></ul></ul><ul><ul><li>Each field is represented as name=value </li></ul></ul><ul><ul><li>Fields are separated by a ' & ' character </li></ul></ul><ul><ul><li>Each name and value is url-encoded </li></ul></ul><ul><ul><ul><li>non-alphanumeric characters are replaced by a hex value &quot;%xx“ </li></ul></ul></ul><ul><li>Use the POST method. </li></ul><ul><ul><li>Often used with forms on web pages. </li></ul></ul>POST /signup.asp HTTP/1.1 Host: www.example.net User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.12)... Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,... Accept-Language: en-us,en;q=0.5 Accept-Encoding: gzip,deflate Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7 Keep-Alive: 300 Connection: keep-alive Content-Type: application/x-www-form-urlencoded Content-Length: 38 name=Jane+Doe&email=jane%40myhost.com
    • 56. How does AJAX work? <ul><li>The kernel of Ajax is the XmlHttpRequest JavaScript object. </li></ul><ul><li>XmlHttpRequest was originally introduced in IE5 </li></ul><ul><li>It is the enabling technology that allows asynchronous requests </li></ul><ul><ul><li>XmlHttpRequest lets use JS to make a request to the server and process the response without blocking the user. </li></ul></ul><ul><li>Before using the XMLHttpRequest object, </li></ul><ul><ul><li>create an instance of it (no standard way for doing this) </li></ul></ul><ul><ul><li>XMLHttpRequest is supported natively by most browsers </li></ul></ul><ul><ul><ul><li>IE is an exception, MS introduced the idea, but as an ActiveX object. </li></ul></ul></ul>
    • 57. XMLHttpRequest Object: Properties If the web server returns an XML document , this will be a DOM document object representing the parsed XML. responseXML A string containing the response data returned from the web server. responseText The text associated with the above HTTP status code . For example, 200 means &quot;OK&quot; and 404 means &quot;Not found&quot;. statusText The numeric HTTP status code returned by the web server. status A number representing the current state of the request readyState
    • 58. XMLHttpRequest Object: Methods Returns a string containing all the response headers. getAllResponseHeaders () Returns the value of the named response header . getResponseHeader (name) Aborts an active request. abort () Makes the request , optionally passing data. send (data) Sets a the named request header . setRequestHeader (name, value) Initializes a new request. method is usually GET or POST . open (method, url, asynch, username, password )
    • 59. Examples of AJAX uses <ul><li>Dynamically update totals on your shopping cart without forcing the user to click Update and wait for the server to resend the entire page . </li></ul><ul><li>Increase site performance by reducing the amount of data downloaded from the server. </li></ul><ul><ul><li>When updating the quantity of an item in a basket, if the entire page is reloaded, forces several KB of data to be downloaded. </li></ul></ul><ul><ul><li>Using Ajax to calculate the new total, the server can respond with just the new total value, thereby reducing the required bandwidth </li></ul></ul><ul><li>Eliminate page refreshes every time there is user input. </li></ul><ul><ul><li>If the user clicks Next on a paginated list, Ajax allows you to just refresh the list with the server data, instead of redrawing the entire page. </li></ul></ul><ul><li>Edit table data directly in place , without requiring the user to navigate to a new page to edit the data. </li></ul><ul><ul><li>When the user clicks Edit, you can redraw the static table into a table with editable contents. </li></ul></ul><ul><ul><li>Once the user clicks Done, you can spawn an Ajax request to update the server, and redraw the table to have static, display-only data. </li></ul></ul>
    • 60. The HttpRequest object <ul><li>Wrapper for XMLHttpRequest </li></ul><ul><ul><li>Hides the browser differences in instantiating the object </li></ul></ul><ul><ul><li>Simplifies the process of making a request and obtaining the response . </li></ul></ul><ul><li>Defined in HttpRequest.js library </li></ul><ul><li>Constructor </li></ul>Creates a new instance of the HttpRequest object. HttpRequest()
    • 61. The HttpRequest object (Properties) These are equivalent to the XMLHttpRequest properties of the same name status, statusText, responseText, responseXML Password for authentication, if required password Username for authentication, if required username A query string to append to the URL queryString The URL to send the request to url A function to be called when a GET or POST request completes unsuccessfully failureCallback A function to be called when a GET or POST request completes successfully successCallback
    • 62. The HttpRequest object (Methods) These are equivalent to the XMLHttpRequest methods of the same name. abort(), setRequestHeader(name, value), getResponseHeader(name), getAllResponseHeaders() Performs an asynchronous POST request, passing the given data post( data ) Performs an asynchronous GET request. get() Removes all request headers. clearRequestHeaders()
    • 63. The HttpRequest JS library <ul><li>Need HttpRequest.js library </li></ul><ul><ul><li>Create HttpRequest object </li></ul></ul><ul><ul><ul><li>var postRequest = new HttpRequest(); </li></ul></ul></ul><ul><ul><li>Define failure callback </li></ul></ul><ul><ul><ul><li>postRequest.failureCallback = requestFailed; </li></ul></ul></ul><ul><ul><ul><li>function requestFailed( httpRequest ){…} </li></ul></ul></ul><ul><ul><li>Perform an asynchronous request </li></ul></ul><ul><ul><ul><li>postRequest. url = address of service ; </li></ul></ul></ul><ul><ul><ul><li>postRequest. queryString =; </li></ul></ul></ul><ul><ul><ul><li>postRequest. successCallback = responseOK; </li></ul></ul></ul><ul><ul><ul><li>postRequest. get (); </li></ul></ul></ul>
    • 64. RESTful WS <ul><li>Web services are practically synonymous with XML </li></ul><ul><li>The application architecture imposed by Ajax and REST techniques has forced many to contemplate alternatives like JSON </li></ul><ul><ul><li>JSON is lighter and more friendly format for Web services clients in the form of a browser (Ajax-enabled application) </li></ul></ul>
    • 65. AJAX and XML <ul><li>Ajax establishes a separate channel on which to send and receive information from remote WS </li></ul><ul><li>If response is an XML </li></ul><ul><ul><li>DOM used for manipulating and processing text </li></ul></ul><ul><ul><ul><li>simple access to a data tree requires numerous method calls </li></ul></ul></ul><ul><ul><ul><li>DOM: differing implementation details among various browsers </li></ul></ul></ul><ul><ul><ul><li>complex programming scheme for cross-browser compatibility </li></ul></ul></ul><ul><li>Need to accommodate WS response to AJAX </li></ul><ul><ul><li>leverage a common component in all mainstream browsers: the JavaScript engine </li></ul></ul><ul><ul><li>JSON fits natively to the JS engine </li></ul></ul>
    • 66. Agenda (cont’d) <ul><li>RESTful WS </li></ul><ul><ul><li>AJAX </li></ul></ul><ul><ul><ul><li>The XmlHttpRequest object </li></ul></ul></ul><ul><ul><ul><li>The HttpRequest object </li></ul></ul></ul><ul><ul><li>JSON </li></ul></ul><ul><ul><ul><li>JSON data structures </li></ul></ul></ul><ul><ul><ul><li>JSON vs XML </li></ul></ul></ul><ul><ul><ul><li>Benefits and lowlights of JSON </li></ul></ul></ul><ul><ul><ul><li>Generating and Consuming JSON </li></ul></ul></ul><ul><ul><li>Demo: JSON and REST-WS </li></ul></ul>
    • 67. JSON <ul><li>JSON stands for JavaScript Object Notation </li></ul><ul><li>Lightweight data-interchange format </li></ul><ul><li>Text Format : easy for humans to read and write </li></ul><ul><li>Trivial for JS engine to parse and generate </li></ul><ul><li>Based on a subset of the JavaScript Programming Language </li></ul><ul><li>JSON is a text format that is completely language independent </li></ul><ul><ul><li>uses conventions familiar to programmers of the C-family of programming languages </li></ul></ul>
    • 68. JSON data structures <ul><li>JSON is built on two structures: </li></ul><ul><ul><li>A collection of name/value pairs . </li></ul></ul><ul><ul><ul><li>In various languages, this is realized as an object , record, struct, dictionary, hash table, keyed list, or associative array. </li></ul></ul></ul><ul><ul><li>An ordered list of values. </li></ul></ul><ul><ul><ul><li>In most languages, this is realized as an array , vector, list, or sequence. </li></ul></ul></ul><ul><li>These are universal data structures. </li></ul><ul><ul><li>Virtually all modern programming languages support them </li></ul></ul>
    • 69. JSON vs XML {&quot;addressbook&quot;: {&quot;name&quot;: &quot;Mary Lebow&quot;, &quot;address&quot;: { &quot;street&quot;: &quot;5 Main Street“, &quot;city&quot;: &quot;San Diego, CA&quot;, &quot;zip&quot;: 91912 }, &quot;phoneNumbers&quot;: [ &quot;619 332-3452&quot;, &quot;664 223-4667&quot; ] } } <addressbook> <name>Mary Lebow</name> <address> <street>5 Main Street</street> <city zip=&quot;91912&quot;> San Diego, CA </city> <phoneNumbers> <phone>619 332-3452</phone> <phone>664 223-4667</phone> </phoneNumbers> </address> </addressbook>
    • 70. JSON Object <ul><li>An object is an unordered set of name/value pairs </li></ul><ul><li>An object begins with {  and ends with }  </li></ul><ul><li>Each name is followed by : and the name/value pairs are separated by ,  </li></ul><ul><li>Example: { firstname : Juan, lastname : Lucero } </li></ul>
    • 71. JSON Array <ul><li>An array is an ordered collection of values </li></ul><ul><li>An array begins with [  and ends with ] </li></ul><ul><li>Values are separated by ,  </li></ul><ul><li>Example: [{ firstname:Juan, lastname:Lucero }, { firstname:Jose, lastname:Perez }] </li></ul>
    • 72. JSON Value <ul><li>A value can be </li></ul><ul><li>Examples: 34, “Joseph”, true, {price:32.2} </li></ul>
    • 73. JSON String <ul><li>A string is a collection of zero or more Unicode characters, wrapped in double quotes </li></ul><ul><li>A character is represented as a single character string. </li></ul>
    • 74. JSON Number <ul><li>A number is very much like a C or Java number </li></ul><ul><li>Octal and hexadecimal formats are not used </li></ul>
    • 75. Benefits of JSON <ul><li>Easier data access </li></ul><ul><ul><li>Same internal representation used by JS engines for data structures like strings, arrays, and objects </li></ul></ul><ul><ul><li>Name access from JSON: addressbook.name </li></ul></ul><ul><ul><li>Street address access from JSON: addressbook.address.street </li></ul></ul><ul><ul><li>First phone number access from JSON: addressbook.address.phoneNumbers[0] </li></ul></ul>{&quot;addressbook&quot;: {&quot;name&quot;: &quot;Mary Lebow&quot;, &quot;address&quot;: { &quot;street&quot;: &quot;5 Main Street“, &quot;city&quot;: &quot;San Diego, CA&quot;, &quot;zip&quot;: 91912 }, &quot;phoneNumbers&quot;: [ &quot;619 332-3452&quot;, &quot;664 223-4667&quot; ] } }
    • 76. Benefits of JSON (cont’d) <ul><li>JSON has a less verbose nature </li></ul><ul><ul><li>XML requires closing tags for markup compliance </li></ul></ul><ul><ul><li>JSON only needs a } </li></ul></ul><ul><ul><li>In data exchanges comprising a hundred or more fields , this additional XML markup can add to transit times </li></ul></ul><ul><li>JSON libraries produced for many languages </li></ul><ul><ul><li>C#, Java, PHP, Haskell, Lisp… </li></ul></ul>
    • 77. Lowlights of JSON <ul><li>Namespaces are missing in JSON </li></ul><ul><li>JSON lacks of attributes </li></ul><ul><li>Creation and validation of JSON may be more complex </li></ul><ul><ul><li>XML has several developing tools for its processing </li></ul></ul>
    • 78. Generating JSON <ul><li>Use a StringBuilder (or similar) class to serialize object </li></ul><ul><li>Use existing DLLs or libraries that perform this task for different languages </li></ul>public class Person { #region Member fields int id = - 1; string name = &quot;&quot;; #endregion #region Properties public int ID { get{return this.id;} set{this.id = value;} } public string Name { get{return this.name;} set{this.name = value;} } #endregion #region Constructors public Person(): this( - 1, &quot;&quot;){} public Person(int id, string name) { this.id = id; this.name = name; } #endregion } public string ToJSON() StringBuilder sb = new StringBuilder(); sb.Append(&quot;{&quot;); sb.AppendFormat(&quot;&quot;{0}&quot;: &quot;{1}&quot;&quot;, this.ID, this.Name); sb.Append(&quot;}&quot;); return sb.ToString(); } Add
    • 79. Consuming JSON <ul><li>On JS, use json.js from json.org to convert a json-formatted string into a json object </li></ul><ul><ul><li>http://www.json.org/json.js </li></ul></ul>function ReadyStateChangeHandler() { if (xmlHttpRequest.readyState == 4) // Completed { if (xmlHttpRequest.status == 200) // Response OK { // Process data var jsonStringObj = xmlHttpRequest.responseText; // Parse the JSON string object to a real JSON object var jsonObj = jsonStringObj. parseJSON (); // display some data alert(&quot;Person Name: &quot; + jsonObj.Name ); } else { alert(&quot;Error: HTTP &quot; + xmlHttpRequest.status + &quot; &quot; + xmlHttpRequest.statusText); } } }
    • 80. JSON and REST-WS demo
    • 81. Agenda (cont’d) <ul><li>Mashups </li></ul><ul><ul><li>Example of mashups </li></ul></ul><ul><ul><li>Mashing up a yahoo map object </li></ul></ul><ul><li>Hands On </li></ul><ul><ul><li>Consuming a REST-WS </li></ul></ul><ul><ul><li>Creating/Adding a mashup </li></ul></ul><ul><li>Wrap up </li></ul>
    • 82. Mashups <ul><li>Web application that combines data from more than one source into a single integrated tool </li></ul>
    • 83. Mashup: Yahoo! Maps API <ul><li>Obtain an application ID </li></ul><ul><ul><li>https://developer.yahoo.com/wsregapp/index.php </li></ul></ul><html> <head> <script type=&quot;text/javascript&quot; src=&quot;http://api.maps.yahoo.com/ajaxymap?v=3.7&appid=YahooDemo&quot;> </script> </head> <body> ... ... </body> </html>
    • 84. Mashup: Yahoo! Maps API <ul><li>Add a div container in which to place the map </li></ul><ul><li>Create a map object and use the drawZoomAndCenter() method to draw the map </li></ul><div id=&quot;map&quot;></div> <script type=&quot;text/javascript&quot;> // Create a map object var map = new YMap(document.getElementById('map')); // Set map type to either of: YAHOO_MAP_SAT, YAHOO_MAP_HYB, YAHOO_MAP_REG map.setMapType(YAHOO_MAP_SAT); // create geopoint var geopoint = new YGeoPoint(latitude,longitude); // Display the map centered on a geocoded location map.drawZoomAndCenter(geopoint, 3); </script>
    • 85. Agenda (cont’d) <ul><li>Mashups </li></ul><ul><ul><li>Example of mashups </li></ul></ul><ul><ul><li>Mashing up a yahoo map object </li></ul></ul><ul><li>Hands On </li></ul><ul><ul><li>Consuming a REST-WS </li></ul></ul><ul><ul><li>Creating/Adding a mashup </li></ul></ul><ul><li>Wrap up </li></ul>
    • 86. JSON / RESTful WS Client <ul><li>WS is located in </li></ul><ul><ul><li>http:// < serverip > :3655/ getLocation_WS .aspx </li></ul></ul><ul><ul><li>Parameters: </li></ul></ul><ul><ul><ul><li>Lat // latitude, use -31.422419 </li></ul></ul></ul><ul><ul><ul><li>Long // longitude, use -64.188183 </li></ul></ul></ul><ul><ul><ul><li>Within // range of interest in meters, e.g. Within=500 </li></ul></ul></ul><ul><li>An html template file is in <serverip> </li></ul><ul><ul><li>Use a ftp client to download it locally, modify it, rename it, and uploaded to the server. Then opening it using IE </li></ul></ul><ul><ul><li>JS Scripts are also located there </li></ul></ul><ul><li>Your job </li></ul><ul><ul><li>Consume the WS, convert the response to a JSON object, and display the answer in the html page </li></ul></ul><ul><ul><li>Play a bit. Resources have url pictures, you can retrieve these pictures from the server too </li></ul></ul>
    • 87. JSON Object object objects elements distance resource id res desc type images img_thumb latitude longitude name
    • 88. Mashing up with Yahoo! Maps <ul><li>A reference card for the API is located in <serverip> </li></ul><ul><li>Your job: </li></ul><ul><ul><li>Place a map centered in ( -31.422419 , -64.188183 ) </li></ul></ul><ul><ul><li>Place markers for each resource on the map using </li></ul></ul><ul><ul><ul><li>YMarker(geopoint); </li></ul></ul></ul><ul><ul><ul><li>addOverlay( m arker); </li></ul></ul></ul><ul><ul><li>Play with addAutoExpand() method </li></ul></ul>
    • 89. Agenda (cont’d) <ul><li>Mashups </li></ul><ul><ul><li>Example of mashups </li></ul></ul><ul><ul><li>Mashing up a yahoo map object </li></ul></ul><ul><li>Hands On </li></ul><ul><ul><li>Consuming a REST-WS </li></ul></ul><ul><ul><li>Creating/Adding a mashup </li></ul></ul><ul><li>Wrap up </li></ul>
    • 90. SOA and WEB 2.0 Convergence
    • 91. XML vs JSON: considerations <ul><li>Which one to use depends mainly on the WS consumer </li></ul><ul><ul><li>Thick WS clients (Java , .NET , PHP, …) should use XML. </li></ul></ul><ul><ul><ul><li>Most programming language environments provide custom libraries, parsers, or helper classes, ... </li></ul></ul></ul><ul><ul><li>Thin WS clients (web-based, AJAX) should consider JSON. </li></ul></ul><ul><ul><ul><li>Processing XML can be tough in this environment </li></ul></ul></ul><ul><ul><ul><li>Programming the DOM is a difficult undertaking when compared to accessing a JSON tree. </li></ul></ul></ul>
    • 92. References <ul><li>SOAP-based Web Services </li></ul><ul><ul><li>Service-Oriented Architecture : A Field Guide to Integrating XML and Web Services, by Thomas Erl, Prentice Hall </li></ul></ul><ul><li>RESTful Web Services </li></ul><ul><ul><li>RESTful Web Services, Richardson et al, O’Reilly </li></ul></ul><ul><li>JSON </li></ul><ul><ul><li>http://www.json.org/ </li></ul></ul><ul><ul><li>http://dev2dev.bea.com/pub/a/2007/02/introduction-json.html </li></ul></ul><ul><li>Yahoo! Maps AJAX API </li></ul><ul><ul><li>http://developer.yahoo.com/maps/ajax/index.html </li></ul></ul>
    • 93. Questions ?
    • 94. Backup
    • 95.  
    • 96. Similarities

    ×