Web Services - PowerPoint PPT Presentation

1 / 50
About This Presentation
Title:

Web Services

Description:

The document style of SOAP relies on XML schemas to designate the format of the ... This style seems to be gaining in poularity and some predict that it will ... – PowerPoint PPT presentation

Number of Views:52
Avg rating:3.0/5.0
Slides: 51
Provided by: pes45
Category:
Tags: services | style | web

less

Transcript and Presenter's Notes

Title: Web Services


1
Web Services
  • Updated by Dr Suthikshn Kumar
  • Suthikshn.kumar_at_pes.edu

2
Contents
  • What is WS?
  • SOAP
  • RPC style SOAP
  • Document Style SOAP
  • WSDL
  • REST Services
  • JSON Format
  • What is JSON?
  • Array Literals
  • Object Literals
  • Mixing Literals
  • JSON Syntax
  • JSON Encoding and Decoding
  • JSON vs XML

3
Introduction
  • When XML use began to take off after 2000,
    businesses, developers, and others looked for new
    ways to use it.
  • The promise of separating content and
    presentation had been met, but how could this
    capability be capitalized upon?
  • The answer was web services.
  • Web services provide a way to exchange data
    between applications and services.
  • To facilitate this communication, web services
    use the internet to send messages composed of XML
    data back and forth between the consumer and
    provider.
  • The major difference with web services is that
    the data being transmitted is XML text instead of
    a binary format.
  • The promise behind web services is that of having
    software components available on demand, to any
    application in the world.
  • Whether that be a web application or a
    traditional desktop application, it is possible
    to use the same service to perform the same task.

4
Related Technologies
  • SOAP( Simple Object Access Protocol) is a
    combination of an XML-based language and any
    number of common protocols for transmitting this
    data.
  • WSDL Web Services Description Language is
    another XML based language that was created to
    describe the usage of a particular web service,
    or rather, how a particular service could be
    called.
  • REST Representation State Transfer, describes
    of using the existing HTTP protocol to transmit
    data.

5
Service Oriented Architecture
  • Service-Oriented Architecture (SOA) expresses a
    software architectural concept that defines the
    use of services to support the requirements of
    software users

6
Service Oriented Architecture
Service Provider
Service Requestor
Internet
Legacy System
Service Broker
7
Requirements for a SOA
  • Interoperability between different systems and
    programming languages
  • Clear and unambiguous description language
  • Retrieval of the service
  • Security

8
Web Services DefinitionW3C
  • A Web service is a software system
  • Identified by a URL, whose public interfaces and
    bindings are defined and described using XML.
  • Its definition can be discovered by other
    software systems
  • These systems may then interact with the Web
    service
  • using XML based messages conveyed by Internet
    protocols
  • Web Services implement a Service Oriented
    Architecture

9
Web Services
  • Web services are an emerging technology that
    offer a solution for providing a common
    collaborative architecture.
  • Web services provide functional building blocks
    which are not tied to any particular programming
    language or hardware platform.
  • They are accessible over standard Internet
    protocols.

10
The Evolution
  • Online systems replace Batch systems
  • Graphical User Interfaces replace green screens
  • Networked systems replace standalone systems
  • Internet based systems replace LAN based systems
  • Future ???
  • Web Services replace simple Internet and LAN
    based systems

11
Technologies
  • XML (eXtensible Markup Language)
  • markup language that underlies most of the
    specifications used for Web services.  
  • SOAP (Simple Object Access Protocol)
  • (Simple Object Access Protocol), similar to JDBC,
    is a network, transport, and programming language
    and platform neutral protocol that allows a
    client to call a remote service. The message
    format is XML.
  • WSDL (Web services description language)
  • An XML-based interface and implementation
    description language. The service provider uses a
    WSDL document in order to specify the operations
    a Web service provides. 
  • UDDI (universal description, discovery, and
    integration)
  • Both a client-side API and a SOAP-based server
    implementation that can be used to store and
    retrieve information on service providers and Web
    services.

12
How it works
  • A Web Service is a URL-addressable software
    resource that performs functions (or a function).
  • Web Services communicate using standard protocol
    known as SOAP (Simple Object Access Protocol).
  • A Web Service is located by its listing in a
    Universal Discovery, Description and Integration
    (UDDI) directory.

13
Integration
What are Web Services good for?
  • In a lot of organizations, the data and logic of
    one application are basically useless to other
    applications.
  • When an application and its data are isolated
    from other applications, we often say that they
    are in silos.
  • Web Services are better at sharing data and
    functions.
  • The result is that the silos come down, and
    previously isolated systems can talk to each
    other.

14
Access
What are they good for?
  • Web Services are especially good at providing
    access through different interfaces.
  • A Web Service can have a dedicated client
    application, but it can also be readily accessed
    through browsers, wireless devices,
    voice-activated interfaces, and so on.
  • Adding new access methods is much simpler than
    with a traditional application.

15
Flexibility
What are they good for?
  • One of the more important innovations in Web
    Services is machine-to-machine communications.
  • This means that a Web Service can ask another Web
    Service to do something, and that Web Service can
    ask another Web Service to do something, and so
    on.
  • In the future, many Web Services will really just
    be aggregations of other Web Services.

16
Application Assembly
What are they good for?
  • Future applications will be assembled from a
    diverse group of web services, aggregating
    functionality.
  • Reusability is extended to the execution level,
    versus reusability from just the design and
    construction level.

17
SOAP
  • Simple Object Access Protocol
  • SOAP is an open protocol specification defining a
    uniform way of performing RPCs using HTTP as the
    underlying communications protocol with XML for
    the data serialization.

18
SOAP
  • The SOAP spec describes an intricate language
    with numerous elements and attributes, intended
    to describe most types of data.
  • This information can be transported over any
    number of protocols, but is most commonly sent
    over HTTP along with other web traffic.
  • There are two ways of using SOAP
  • Remote procedure call style
  • Document Style

19
RPC-Style SOAP
  • The RPC style of SOAP treats the web service as
    though it were an object containing one or more
    methods.
  • A request is made to the service detailing the
    method name to call and the parameters if any to
    pass.
  • The method is executed on the server and an XML
    response is dispatched containing the return
    value, if any.

20
RPC-Style SOAP example
  • A web service that provides simple arithmetic
    ops addition, subtraction, multiplication and
    division. Each method takes two numbers and
    returns a result.
  • An RPC style request for the add operation would
    look like this
  • lt?xml version 1.0 encoding utf-8 ?gt
  • ltsoapEnvelope xmlnssoap http//schemas.xmlsoap
    .org/soap/envelope
  • soapencodingStyle http//schemas.xmlsoap.org/s
    oap/encoding/gt
  • ltsoapBodygt
  • ltwadd xmlnsw http//www.wrox.com/services/mat
    h gt
  • ltwop1gt4.5lt/wop1gt
  • ltwop2gt5.4lt/wop2gt
  • lt/waddgt
  • lt/soapBodygt
  • lt/soapEnvelopegt

21
RPC-style SOAP response
  • If the request to add two numbers executed
    successfully, the response message would look
    like
  • lt?xml version 1.0 encoding utf-8 ?gt
  • ltsoapEnvelope xmlnssoap http//schemas.xmlsoap
    .org/soap/envelope
  • soapencodingStyle http//schemas.xmlsoap.org/s
    oap/encoding/gt
  • ltsoapBodygt
  • ltwaddReponse xmlnsw http//www.wrox.com/servic
    es/math gt
  • ltwaddResultgt9.9lt/waddResultgt
  • lt/waddResponsegt
  • lt/soapBodygt
  • lt/soapEnvelopegt
  • If there were any problems processing the SOAP
    request on the server, then a ltsoapFaultgt
    element will be returned.

22
Document-Style SOAP
  • The document style of SOAP relies on XML schemas
    to designate the format of the request and
    response.
  • This style seems to be gaining in poularity and
    some predict that it will eventually all but
    replace the RPC style.
  • A document-style request may not look that
    different from an RPC-style request. ( simply
    remove the soapencodingStyle attribute)
  • lt?xml version 1.0 encoding utf-8 ?gt
  • ltsoapEnvelope xmlnssoap http//schemas.xmlsoap
    .org/soap/envelope gt
  • ltsoapBodygt
  • ltwadd xmlnsw http//www.wrox.com/services/mat
    h op1 4.5 op2 5.4 /gt
  • lt/soapBodygt
  • lt/soapEnvelopegt

23
WSDL
  • Web Services Description Language
  • WSDL is XML-based language
  • Was created to describe the usage of a particular
    web service, how a particular service could be
    called.
  • The WSDL specification describes an incredibly
    dense language, designed to be extremely flexible
    and allow for as much re-use as possible.
  • Typically, a software tool is used for the
    initial WSDL file creation and then hand tweaked
    as necessary.

24
Difference between Document Style and RPC style
SOAP
  • The Document Style sends the message as elements
    within the ltsoapbodygt that can have whatever
    structure the sender and receiver agree on using
    the embedded schema as a guide.
  • An RPC-style message had an element named after
    the method being called. This in turn will have
    one element for each parameter the method
    accepts.

25
REST ( Representation State Transfer)
  • Describes a way of using the existing HTTP
    protocol to transmit data.
  • REST can be used for any type of HTTP based
    request and response systems as well.
  • With regard to web services, REST enables you to
    call a given URL in a specific format to return
    the data.

26
REST example
  • Wrox would like to provide a way for others to
    retriev a list of all authors. REST style web
    service use simple URLs to access data the wrox
    book service could use this URL to retrieve the
    list of authors
  • http//www.wrox.com/services/authors
  • This service may return an XML representation of
    the known authors along with information on how
    to access details about each one, such as
  • lt?xml version 1.0 encoding utf-8 ?gt
  • ltauthors xmlnsxlink http//www/w3.org/1999/xlink
  • Xmlns http//www.wrox.com/services/authors-books
  • Xlinkhrefhttp//www.wrox.com/services/authors/gt
  • ltauthor forenames Michael surname kay
  • xlinkhref http//www.wrox.com/services/authors/
    kaym
  • id fawcettj /gt
  • lt! More authors --- gt
  • lt/authorsgt

27
REST example contd
  • Xlink is a way of linking documents that goes way
    beyond the straightforward hyperlinks in HTML. It
    provides capabilities to specify a two-way
    dependency so that documents can be accessible
    from each other as well as indicating how a link
    should be activated for exmaple by hand,
    automatically or after a preset time.
  • If used in a web site or web application, the XML
    returned from the REST service would be
    transformed either client side or server-side to
    a more user-friendly format
  • lthtmlgt
  • ltheadgt
  • lttitlegt Wrox Authors lt/titlegt
  • lt/headgt
  • ltbodygt
  • lta href http//www.wrox.com/services/authors/kay
    mgtMichael Kaylt/agt
  • lta href http//www.wrox.com/services/authors/faw
    cettjgtJoe Fawcettlt/agt
  • lt/bodygt
  • lt/htmlgt

28
How Is a Service Described?
  • WSDL (Web Service Description Language)
  • XML-based
  • Submitted to W3C for standardization
  • Terraserver example
  • httpterraserver.microsoft.com/default.aspx

29
How Do I Find Web Services?
  • UDDI project by Microsoft, IBM, and others. Take
    a look at //uddi.org
  • Websites
  • //www.xmethods.net
  • //www.salcentral.com
  • Commercial
  • //www.serviceobjects.com
  • //www.xmethods.net

30
ServiceObjects
31
FastWeather
32
Using the FastWeather Web Service
ServiceObjectsWeb Service
RV Application
Internet
33
WebSphere Studio Wizards
  • Wizards make it easy for you to create and use
    Web Services
  • Wizard to create a Web Service from a JavaBean
  • Generates WSDL document
  • Creates all required software components
  • Create a Test client
  • Wizard to create a Web Service Client
  • Use the WSDL document as input

34
Generate a Web Service Client
35
Client Configuration
36
Web Service Selection
37
Web Service Client Test
38
Testing
Input.jsp
Method.jsp
Result.jsp
39
Web Service HTML File
40
weather.html
ltIFRAME src"Input.jsp?method13" nameinput
scrolling"no" frameborder"0" align"top"
height"350"gt lt/IFRAMEgt ltIFRAME
src"Result.jsp" name"result" scrolling"no"
frameborder"0" align top height"350"gt
41
weather.html
42
Web Service as part of RV Application
43
Lab Exercises
  • Create Web Services client
  • Integrate Web Service into the RV application

44
JSON
  • JSON - JavaScript Object Notation
  • Tutorial of this simple and universal data
    exchange format
  • JSON is a part of the ECMAScript standard since
    ECMA has defined in 1999 the eval() function that
    parses the format.It has been popularized with
    the success of Ajax. The JSON word appears often
    when one is speaking about Ajax. We know this is
    another data format, that can replace XML, and
    this format is supported by a lot of programmers.
    But what is exactly JSON, what are the
    advantages?
  • Content
  • Why JSON?
  • JSON and XML
  • The syntax of JSON
  • Example of JSON file
  • How to use the format
  • Client side (browser)
  • Server side
  • Data exchange
  • Example
  • Simple demo
  • YAML and JSON
  • Resources

45
Why JSON
  • Why JSON?
  • The benefit of JSON is that it is recognized
    natively by JavaScript. No need for parsing an
    XML document to extract the data and get it
    throught the net.
  • JSON and XML
  • Benefits of JSON - The easiness of reading.-
    The easiness of using.Benefits of XML- XML is
    extensible.- It is widely used and recognized by
    almost all programming languages. Unfortunally,
    both XML and JSON are enable to integrate a large
    amount of data in binary form.

46
The syntax of JSON
  • The components of JSON- An object contains
    objets or attributes.- A scalar variable
    Number, String, Boolean.- An array.- Literal
    values null, true, false, "string of
    characters", and numerical values.
  • Object
  • It contains a member or a list of members, and
    each member has the form
  • "name" "value" The syntax of the object is
  • member, member, .... Array
  • A collection of values, separated by commas.
    value, value, .... Values
  • A value may be an object, an array, a litteral
    (string, number, true, false, null).
  • Nothing more is required to create a JSON file!

47
Example
  •    "menu" "File",    "commands"       
               "title" "New",           
    "action""CreateDoc"       ,       
               "title" "Open",           
    "action" "OpenDoc"       ,       
               "title" "Close",          
    "action" "CloseDoc"            

48
XML Equivalent
  • lt?xml version"1.0" ?gt ltrootgt  
    ltmenugtFilelt/menugt   ltcommandsgt     
    ltitemgt          lttitlegtNewlt/valuegt         
    ltactiongtCreateDoclt/actiongt      lt/itemgt     
    ltitemgt          lttitlegtOpenlt/valuegt         
    ltactiongtOpenDoclt/actiongt      lt/itemgt     
    ltitemgt          lttitlegtCloselt/valuegt         
    ltactiongtCloseDoclt/actiongt      lt/itemgt  
    lt/commandsgt lt/rootgt

49
How to use the format
  • The JSON file allows to load data from the server
    or to send data to it, in this format. For
    example, storing the content of a form, just
    filled by an user. This involves three steps the
    browser processing, the server processing, and
    the data exchange between them.
  • Client side (browser)
  • This is rather easy, as JSON is a part of the
    JavaScript definition. The content of a file, or
    the definition of the data is assigned to a
    variable, and this variable becomes an object of
    the program.
  • Server side
  • JSON file are used by various programming
    languages, including PHP and Java thanks to
    parsers that allow to get the content and that
    may even convert it into classes and attributes
    of the language.The json.org includes a C parser
    and a list of parsers in other languages.
  • Data exchange
  • Loading a file may be accomplished from
    JavaScript in several ways- direct including of
    the file into the HTML page, as a JavaScript .js
    external file.- loading by a JavaScript
    command.- using XMLHttpRequest.The JSON file is
    parsed by the eval() JavaScript
    function.Sending the file to the server may be
    accomplished by XMLHttpRequest. The file is sent
    as a text file and processed by the parser of the
    programming language that uses it.

50
Example
  • The XMLHttpRequest code
  • var req new XMLHttpRequest()
  • req.open("GET", "file.json", true)
  • req.onreadystatechange myCode // the handler
  • req.send(null)
  • The JavaScript handler
  • function myCode()
  • if (req.readyState 4)
  • var doc eval('(' req.responseText ')')
  • Using the data
  • var menuName document.getElementById('jsmenu')
    // finding a field menu
  • Name.value doc.menu.value // assigning a value
    to the field
  • How to access data
  • doc.commands0.title // read value of the
    "title" field in the array
  • doc.commands0.action // read value of the
    "action" field in the array
Write a Comment
User Comments (0)
About PowerShow.com