Web Services - PowerPoint PPT Presentation

About This Presentation
Title:

Web Services

Description:

Example Scenario Online Trade. Book Store. The Hobbit (5) Price: 25.95. Copies in Stock: 1 ... Example: Currency Rate. There are many available Web services ... – PowerPoint PPT presentation

Number of Views:33
Avg rating:3.0/5.0
Slides: 97
Provided by: csHu
Category:

less

Transcript and Presenter's Notes

Title: Web Services


1
Web Services
  • Representation and Management of Data on the Web

2
"Web services are loosely coupled software
components delivered over Internet standard
technologies."
3
Example Scenario Get Online Information
Stock Broker Application
Stock Exchange
4
Example Scenario Online Trade
Book Store
The Hobbit (5) Price 25.95 Copies in Stock 1
The Hobbit (5) Price 25.95 Copies in Stock 0
5
Example ScenarioGrid Computation
Grid Computation
Using seamlessly the combined resources of many
computers that are connected to the Internet
6
What is a Web Service?
  • Self-contained, modular Web application that can
    be published, located and invoked across the Web
  • A Web service can perform functions of varying
    complexities
  • Once deployed, other applications (and other Web
    services) can discover and invoke the deployed
    service

7
Why is it Difficult to Use Ordinary Web Sites as
Services?
  • Consider an application that should return the
    price of the book The Hobbit
  • How can your application find suitable online
    stores?
  • How can your application find the price of the
    book in a Web page?
  • How can your application fill forms, if needed?

8
How can we find this URL?
What is the price here?
9
Calling Remote FunctionsCould Help
  • It would help if we could call functions, such
    as
  • Amazon.getPrice(The Hobbit")
  • Amazon.buyBook(The Hobbit", myId)

getPrice()
The Internet
10
Difficulties in UsingRemote Functions
  • How can the calling application know in what
    language the functions are written?
  • How can the application know what functions are
    available and what are their signatures?
  • How can an application call a function that
    resides behind a firewall?

11
The Solution
  • Use an agreed interface and a syntax that all
    applications are familiar with (e.g., XML)
  • For example, SOAP
  • Use HTTP to transfer data through port 80
  • Use a standard for publishing methods, their
    signatures and their usage
  • For example, WSDL
  • Use standard directory structures for publishing
    available services
  • For example, UDDI

12
(No Transcript)
13
Web Services that areAlready Available
  • Google search (http//www.google.com/apis)
  • Weather reports
  • Stock prices
  • Currency exchanges
  • Sending SMS messages, faxes
  • Prices of books in Barnes and Nobles
  • Dictionaries
  • etc.

14
Implementing Web Services
  • Programmers are given tools that spare the need
    to directly write SOAP or WSDL documents
  • In Java
  • JAX-RPC part of SUN tools for publishing and
    deploying Web Services
  • AXIS Apaches tool for handling Web services in
    Java

15
SOAPSimple Object-Access Protocol
16
What is SOAP?
  • SOAP is a protocol for accessing Web Services
  • SOAP is XML based
  • Thus, SOAP provides interoperability
  • In SOAP, applications exchange information over
    HTTP
  • Thus, SOAP is not restricted by firewalls
  • SOAP allows to exchange structured and typed
    information on the Web
  • XSchema types are used to add types to XML
  • SOAP specification http//www.w3.org/2000/xp/Grou
    p/

17
POST /soap HTTP/1.0 SOAPAction
"" Content-Length 520 lt?xml version"1.0"
encoding"UTF-8"?gt ltsoapenvEnvelope
xmlnssoapenv"http//schemas.xmlsoap.org/soap/e
nvelope/" xmlnsxsd"http//www.w3.o
rg/2001/XMLSchema"
xmlnsxsi"http//www.w3.org/2001/XMLSchema-instan
ce"gt ltsoapenvBodygt ltns1getRate
soapenvencodingStyle"http//schemas.xmlsoap.o
rg/soap/encoding/" xmlnsns1"urnxmethod
s-CurrencyExchange"gt ltcountry1
xsitype"xsdstring"gtEurolt/country1gt
ltcountry2 xsitype"xsdstring"gtIsraellt/country2gt
lt/ns1getRategt lt/soapenvBodygt lt/soapenvEnvel
opegt
A request to http//services.xmethods.net80/soap
18
HTTP/1.0 200 OK Date Sat, 07 May 2005 232621
GMT Content-Length 492 Content-Type
text/xml lt?xml version'1.0' encoding'UTF-8'?gt lt
soapEnvelope xmlnssoap'http//schemas.xml
soap.org/soap/envelope/'
xmlnsxsi'http//www.w3.org/2001/XMLSchema-instan
ce' xmlnsxsd'http//www.w3.org/2001/XMLS
chema' xmlnssoapenc'http//schemas.xmlsoap
.org/soap/encoding/' soapencodingStyle'htt
p//schemas.xmlsoap.org/soap/encoding/'gt
ltsoapBodygt ltngetRateResponse
xmlnsn'urnxmethods-CurrencyExchange'gt
ltResult xsitype'xsdfloat'gt5.5825lt/Res
ultgt lt/ngetRateResponsegt
lt/soapBodygt lt/soapEnvelopegt
The Response
19
A SOAP Message
  • A SOAP message is an ordinary XML document
    containing the following elements
  • Envelope identifies the XML document as a SOAP
    message required
  • Header contains header information optional
  • Body contains call or response information
    required
  • Fault provides information about errors that
    occurred while processing the message optional

20
SOAP Simplification (1)
  • Consider the Java interface
  • Suppose that a client wants to call the server's
    sayHelloTo method
  • Could send an XML message

public interface Hello public String
sayHelloTo(String name)
lt?xml version"1.0"?gtltHellogt    ltsayHelloTogt   
     ltnamegtLisalt/namegt    lt/sayHelloTogtlt/Hellogt
21
SOAP Simplification (2)
  • The Server could respond with

lt?xml version"1.0"?gtltHellogt    ltsayHelloToRespo
nsegt       ltmessagegtHello Lisa, How are
you?lt/messagegt    lt/sayHelloToResponsegtlt/Hellogt
22
SOAP Intuition
23
Skeleton SOAP Message
lt?xml version"1.0"?gt ltsoapEnvelope
xmlnssoap"http//schemas.xmlsoap.org/soap/envelo
pe/" soapencodingStyle"http//schemas.xmlsoap.or
g/soap/encoding/"gt ltsoapHeadergt ... ...
lt/soapHeadergt ltsoapBodygt ... ...
ltsoapFaultgt ... ... lt/soapFaultgt
lt/soapBodygt lt/soapEnvelopegt
Envelope
Header
Body
Fault
24
encodingStyle Attribute
  • The SOAP encodingStyle attribute indicates the
    encoding rules used to serialize parts of a SOAP
    message
  • Needed when sending data structures
  • This attribute may appear on any SOAP element,
    and it will apply to that element's content and
    all child elements
  • A SOAP message has no default encoding
  • Unencoded data may be used in SOAP messages
  • The SOAP default XMLSchema for SOAP encoding and
    data types is
  • http//www.w3.org/2002/12/soap-encoding
  • Other encoding rules may be used

25
Actual Soap Request
  • ltSOAP-ENVEnvelope
  • xmlnsSOAP-ENV"http//schemas.xmlsoap.org/soap
    /envelope/"
  • xmlnsxsi"http//www.w3.org/1999/XMLSchema-ins
    tance"
  •    xmlnsxsd"http//www.w3.org/1999/XMLSchema"gt 
       ltSOAP-ENVHeadergt lt/SOAP-ENVHeadergt    ltSOAP-
    ENVBodygt         ltns1sayHelloTo
     xmlnsns1"Hello"
  • SOAP-ENVencodingStyle"
  • http//schemas.xmlsoap.org/s
    oap/encoding/"gt           ltname
    xsitype"xsdstring"gtLisalt/namegt        
    lt/ns1sayHelloTogt    lt/SOAP-ENVBodygt
  • lt/SOAP-ENVEnvelopegt

26
Actual Soap Request
  • ltSOAP-ENVEnvelope
  • xmlnsSOAP-ENV"http//schemas.xmlsoap.org/soap
    /envelope/"
  • xmlnsxsi"http//www.w3.org/1999/XMLSchema-ins
    tance"
  •    xmlnsxsd"http//www.w3.org/1999/XMLSchema"gt 
       ltSOAP-ENVHeadergt lt/SOAP-ENVHeadergt    ltSOAP-
    ENVBodygt         ltns1sayHelloTo
     xmlnsns1"Hello"
  • SOAP-ENVencodingStyle"
  • http//schemas.xmlsoap.org/s
    oap/encoding/"gt           ltname
    xsitype"xsdstring"gtLisalt/namegt        
    lt/ns1sayHelloTogt    lt/SOAP-ENVBodygt
  • lt/SOAP-ENVEnvelopegt

27
Actual Soap Request
  • ltSOAP-ENVEnvelope
  • xmlnsSOAP-ENV"http//schemas.xmlsoap.org/soap
    /envelope/"
  • xmlnsxsi"http//www.w3.org/1999/XMLSchema-ins
    tance"
  •    xmlnsxsd"http//www.w3.org/1999/XMLSchema"gt 
       ltSOAP-ENVHeadergt lt/SOAP-ENVHeadergt    ltSOAP-
    ENVBodygt         ltns1sayHelloTo
     xmlnsns1"Hello"
  • SOAP-ENVencodingStyle"
  • http//schemas.xmlsoap.org/s
    oap/encoding/"gt           ltname
    xsitype"xsdstring"gtLisalt/namegt        
    lt/ns1sayHelloTogt    lt/SOAP-ENVBodygt
  • lt/SOAP-ENVEnvelopegt

28
Actual Soap Request
  • ltSOAP-ENVEnvelope
  • xmlnsSOAP-ENV"http//schemas.xmlsoap.org/soap
    /envelope/"
  • xmlnsxsi"http//www.w3.org/1999/XMLSchema-ins
    tance"
  •    xmlnsxsd"http//www.w3.org/1999/XMLSchema"gt 
       ltSOAP-ENVHeadergt lt/SOAP-ENVHeadergt    ltSOAP-
    ENVBodygt         ltns1sayHelloTo
     xmlnsns1"Hello"
  • SOAP-ENVencodingStyle"
  • http//schemas.xmlsoap.org/s
    oap/encoding/"gt           ltname
    xsitype"xsdstring"gtLisalt/namegt        
    lt/ns1sayHelloTogt    lt/SOAP-ENVBodygt
  • lt/SOAP-ENVEnvelopegt

29
Actual Soap Response
  • ltSOAP-ENVEnvelope
  • xmlnsSOAP-ENV"http//schemas.xmlsoap.org/soap
    /envelope/"
  •    xmlnsxsi"http//www.w3.org/1999/XMLSchema-ins
    tance"
  • xmlnsxsd"http//www.w3.org/1999/XMLSchema"gt 
       ltSOAP-ENVBodygt          ltns1sayHelloToRespon
    se xmlnsns1"Hello"                SOAP-ENVenco
    dingStyle"
  • http//schemas.xmlsoap.org
    /soap/encoding/"gt                 ltreturn
    xsitype"xsdstring"gt
  • Hello Lisa, How are you doing?
  • lt/returngt          lt/ns1sayHelloToResponsegt 
       lt/SOAP-ENVBodygt
  • lt/SOAP-ENVEnvelopegt

30
Actual Soap Response
  • ltSOAP-ENVEnvelope
  • xmlnsSOAP-ENV"http//schemas.xmlsoap.org/soap
    /envelope/"
  •    xmlnsxsi"http//www.w3.org/1999/XMLSchema-ins
    tance"
  • xmlnsxsd"http//www.w3.org/1999/XMLSchema"gt 
       ltSOAP-ENVBodygt          ltns1sayHelloToRespon
    se xmlnsns1"Hello"                SOAP-ENVenco
    dingStyle"
  • http//schemas.xmlsoap.org
    /soap/encoding/"gt                 ltreturn
    xsitype"xsdstring"gt
  • Hello Lisa, How are you doing?
  • lt/returngt          lt/ns1sayHelloToResponsegt 
       lt/SOAP-ENVBodygt
  • lt/SOAP-ENVEnvelopegt

Body
31
Actual Soap Response
  • ltSOAP-ENVEnvelope
  • xmlnsSOAP-ENV"http//schemas.xmlsoap.org/soap
    /envelope/"
  •    xmlnsxsi"http//www.w3.org/1999/XMLSchema-ins
    tance"
  • xmlnsxsd"http//www.w3.org/1999/XMLSchema"gt 
       ltSOAP-ENVBodygt          ltns1sayHelloToRespon
    se xmlnsns1"Hello"                SOAP-ENVenco
    dingStyle"
  • http//schemas.xmlsoap.org
    /soap/encoding/"gt                 ltreturn
    xsitype"xsdstring"gt
  • Hello Lisa, How are you doing?
  • lt/returngt          lt/ns1sayHelloToResponsegt 
       lt/SOAP-ENVBodygt
  • lt/SOAP-ENVEnvelopegt

32
SOAP Header Element
  • The SOAP Header element is optional
  • It 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
  • Attributes that the namespace defines
  • Actor used to address the Header element to a
    particular server (e.g., proxy) on the message
    path through the Internet
  • mustUnderstand used to indicate whether a
    header entry is mandatory or optional for the
    recipient to process
  • encodingStyle as explained before

33
SOAP Header Element
  • Example
  • ltSOAP-ENVHeadergt     lttTransaction
    xmlnst"some-URI"
  • SOAP-ENVmustUnderstand"1"gt5lt/tTransa
    ctiongt
  • lt/SOAP-ENVHeadergt
  • 5 is the transaction ID of which this method is a
    part
  • In the above example, the SOAP-envelope attribute
    mustUnderstand is set to 1, which means that the
    server must either understand and honor the
    transaction request or must fail to process the
    message

34
SOAP Response on Error
  • There can be many errors in processing a SOAP
    request
  • Error in Running Methods For example, suppose
    that the "Hello Server" does not allow anyone to
    say hello on Tuesday
  • Error in Processing SOAP Headers For example, a
    problem running the method as part of a
    transaction

35
The Fault Element May Include the Following
Sub-Elements
  • ltfaultcodegt A code for identifying the fault
  • ltfaultstringgt A human readable explanation of
    the fault
  • ltfaultactorgt Information about who caused the
    fault
  • ltdetailgt Holds application-specific error
    information related to the Body element of the
    SOAP request

36
SOAP Fault Codes
  • VersionMismatch Found an invalid namespace for
    the SOAP Envelope element
  • MustUnderstand An immediate child element of the
    Header element, with the mustUnderstand attribute
    set to 1, was not understood
  • Client The message was incorrectly formed or
    contained incorrect information
  • Server There was a problem with the server so
    the message could not proceed

37
SOAP Error Response for Method Error
  • ltSOAP-ENVEnvelope xmlnsSOAP-ENV"http//schemas
    .xmlsoap.org/soap/envelope/"gt  
    ltSOAP-ENVBodygt       ltSOAP-ENVFaultgt          
    ltfaultcodegtSOAP-ENVServerlt/faultcodegt          
    ltfaultstringgtServer Errorlt/faultstringgt         
      ltdetailgt               ltemyfaultdetails
    xmlnse"Hello"gt                
    ltmessagegt                   Sorry, I cannot say
    hello on Tuesday.                
    lt/messagegt                 lterrorcodegt1001lt/error
    codegt               lt/emyfaultdetailsgt         
      lt/detailgt       lt/SOAP-ENVFaultgt  
    lt/SOAP-ENVBodygtlt/SOAP-ENVEnvelopegt

38
SOAP Error Response for Header Error
  • ltSOAP-ENVEnvelope xmlnsSOAP-ENV"http//schemas
    .xmlsoap.org/soap/envelope/"gt  
    ltSOAP-ENVBodygt       ltSOAP-ENVFaultgt          
    ltfaultcodegtSOAP-ENVMustUnderstandlt/faultcodegt  
             ltfaultstringgtSOAP Must Understand
    Errorlt/faultstringgt      
    lt/SOAP-ENVFaultgt   lt/SOAP-ENVBodygtlt/SOAP-ENVE
    nvelopegt

No detail element may appear when there is an
error in processing the Headers of a SOAP request
39
Sending a Request
  • The SOAP request does not contain the address to
    which it should be sent
  • Q Where do we put the URL of the Web Service?
  • A It depends on the Protocol used to send the
    request (usually HTTP, but could also be another
    protocol, e.g., SMTP)

40
SOAP Request via HTTP
  • POST http//www.Hello.com/HelloApplication
    HTTP/1.0
  • Content-Type text/xml charsetUTF-8
  • Content-Length 587
  • SOAPAction urnhelloApp
  • ltSOAP-ENVEnvelope

Note There are 2 addresses (1) URL of a SOAP
Server (2) URI of an application to run (this
needn't correspond to an
actual Internet address)
41
SOAPAction Header
  • Used to indicate the intent of the SOAP HTTP
    request
  • The presence and content of the SOAPAction header
    field can be used by servers, such as firewalls,
    to appropriately filter SOAP request messages in
    HTTP
  • The header-field value of an empty string ("")
    means that the intent of the SOAP message is
    provided by the URL of the HTTP Request

42
SOAP Response via HTTP
  • HTTP/1.0 200 OK
  • Content-Type text/xml charsetUTF-8
  • Content-Length 615
  • ltSOAP-ENVEnvelope

43
Example Currency Rate
  • There are many available Web services that you
    can use
  • See http//www.xmethods.com/ for a list
  • Look, in particular, at those marked "RPC"
    (Remote Procedure Call)
  • To get Currency exchange, for example, you can do
    "telnet wwwproxy.cs.huji.ac.il 8080" and then
    send the following request

44
  • POST http//services.xmethods.net80/soap
    HTTP/1.0
  • Content-Type text/xml
  • Content-Length 485
  • SOAPAction ""
  • ltSOAP-ENVEnvelope xmlnsSOAP-ENV"http//schemas.
    xmlsoap.org/soap/envelope/" xmlnsxsi"http//www.
    w3.org/1999/XMLSchema-instance"
    xmlnsxsd"http//www.w3.org/1999/XMLSchema"gt
  • ltSOAP-ENVBodygt
  • ltns1getRate xmlnsns1"urnxmethods-CurrencyExcha
    nge" SOAP-ENVencodingStyle"http//schemas.xmlsoa
    p.org/soap/encoding/"gt
  • ltcountry1 xsitype"xsdstring"gtUnited
    Stateslt/country1gt
  • ltcountry2 xsitype"xsdstring"gtIsraellt/country2gt
  • lt/ns1getRategt
  • lt/SOAP-ENVBodygtlt/SOAP-ENVEnvelopegt

45
And Here is the Response
  • HTTP/1.0 200 OK
  • Content-Type text/xml
  • lt?xml version'1.0' encoding'UTF-8'?gt
  • ltsoapEnvelope xmlnssoap'http//schemas.xmlsoap.
    org/soap/envelope/' xmlnsxsi'http//www.w3.org/1
    999/XMLSchema-instance' xmlnsxsd'http//www.w3.o
    rg/1999/XMLSchema' xmlnssoapenc'http//schemas.x
    mlsoap.org/soap/encoding/' soapencodingStyle'htt
    p//schemas.xmlsoap.org/soap/encoding/'gt
  • ltsoapBodygtltngetRateResponse
  • xmlnsn'urnxmethods-CurrencyExchange'gt
  • ltResult xsitype'xsdfloat'gt4.521lt/Resultgt
  • lt/ngetRateResponsegt
  • lt/soapBodygtlt/soapEnvelopegt

46
Example - Calling Google Spelling
  • lt?xml version"1.0" encoding"UTF-8" ?gt
  • ltSOAP-ENVEnvelope xmlnsSOAP
  • ENVhttp//schemas.xmlsoap.org/soap/envelope/
  • xmlnsxsihttp//www.w3.org/1999/XMLSchema-inst
    ance
  • xmlnsxsdhttp//www.w3.org/1999/XMLSchemagt
  • ltSOAP-ENVBodygt
  • ltns1doSpellingSuggestion xmlnsns1urnGoogl
    eSearch SOAP- ENVencodingStyle"http//schemas.
    xmlsoap.org/soap/encoding/"gt 
  • ltkey xsitype"xsdstring"gt00000000000000000
    000000000lt/keygt  
  • ltphrase xsitype"xsdstring"gtbritney
    speerslt/phrasegt  
  • lt/ns1doSpellingSuggestiongt 
  • lt/SOAP-ENVBodygt 
  • lt/SOAP-ENVEnvelopegt

47
Example - Google Spelling Response
  • lt?xml version"1.0" encoding"UTF-8" ?gt
  • ltSOAP-ENVEnvelope xmlnsSOAP
    ENV"http//schemas.xmlsoap.org/soap/envelope/"
  • xmlnsxsi"http//www.w3.org/1999/XMLSchem
    a-instance"
  • xmlnsxsd"http//www.w3.org/1999/XMLSchem
    a"gt
  • ltSOAP-ENVBodygt
  • ltns1doSpellingSuggestionResponse
    xmlnsns1"urnGoogleSearch
  • SOAP-ENVencodingStyle"http//schemas.xmls
    oap.org/soap/encoding/"gt 
  • ltreturn xsitype"xsdstring"gtbritney
    spearslt/returngt  
  • lt/ns1doSpellingSuggestionResponsegt 
  • lt/SOAP-ENVBodygt 
  • lt/SOAP-ENVEnvelopegt

48
An alternative to SOAP XML-RPC
  • XML-RPC is similar to SOAP but simpler
  • You just have to specify what is the method and
    what are the parameters
  • See http//www.xmlrpc.com for further details

49
XML-RPC Request Example
  • POST /MyRPC HTTP/1.0
  • Host www.cs.huji.ac.il
  • Content-Type text/xml
  • Content-length 181
  • lt?xml version"1.0"?gt
  • ltmethodCallgt ltmethodNamegtHello.sayHelloTolt/methodN
    amegt
  • ltparamsgt
  • ltparamgt
  • ltvaluegtltstringgtLisalt/stringgtlt/valuegt
    lt/paramgt
  • lt/paramsgt
  • lt/methodCallgt

50
XML-RPC Response Example
  • HTTP/1.1 200 OK
  • Connection close
  • Content-Length 158
  • Content-Type text/xml
  • Date Sun, 6 Jun 2004 103308 GMT
  • lt?xml version"1.0"?gt
  • ltmethodResponsegt
  • ltparamsgt
  • ltparamgt
  • ltvaluegtltstringgtHello Lisalt/stringgtlt/valuegt
    lt/paramgt
  • lt/paramsgt
  • lt/methodResponsegt

51
Example 1 MD5 Transform
52
Example 2 Baghdad Weather
53
Example 2 Baghdad Weather
54
Example 3 World Cities
55
Example 3 World Cities
56
WSDL Web Services Description Language
57
Describing a Web Service
  • Need a standard way to describe a Web Service
  • the methods available
  • their parameters
  • etc.
  • WSDL is a standard for describing Web services
    using XML, i.e., it is a language for the green
    pages of UDDI
  • WSDL specification can be found at
    http//www.w3.org/TR/wsdl

58
WSDL Can Describe
  • What a Web service can do
  • Where it resides
  • How to invoke it

59
lt?xml version"1.0"?gt ltdefinitions
name"CurrencyExchangeService"
targetNamespace"http//www.xmethods.net/sd/Curren
cyExchangeService.wsdl" xmlnstns"http//www.x
methods.net/sd/CurrencyExchangeService.wsdl"
xmlnsxsd"http//www.w3.org/2001/XMLSchema"
xmlnssoap"http//schemas.xmlsoap.org/wsdl/soap/"
xmlns"http//schemas.xmlsoap.org/wsdl/"gt
ltmessage name"getRateRequest"gt ltpart
name"country1" type"xsdstring"/gt ltpart
name"country2" type"xsdstring"/gt
lt/messagegt ltmessage name"getRateResponse"gt
ltpart name"Result" type"xsdfloat"/gt
lt/messagegt ltportType name"CurrencyExchangePort
Type"gt ltoperation name"getRate"gt
ltinput message"tnsgetRateRequest"
name"getRate"/gt ltoutput
message"tnsgetRateResponse" name"getRateRespo
nse"/gt lt/operationgtlt/portTypegt
60
ltbinding name"CurrencyExchangeBinding"
type"tnsCurrencyExchangePortType"gt
ltsoapbinding style"rpc" transport"http//schema
s.xmlsoap.org/soap/http"/gt ltoperation
name"getRate"gt ltsoapoperation
soapAction""/gt ltinput name"getRate"gt
ltsoapbody use"encoded" namespace"urnxmethods-
CurrencyExchange"
encodingStyle"http//schemas.xmlsoap.org/soap/enc
oding/"/gt lt/inputgt ltoutput
name"getRateResponse"gt ltsoapbody
use"encoded" namespace"urnxmethods-CurrencyExch
ange" encodingStyle"http//schemas.
xmlsoap.org/soap/encoding/"/gt lt/outputgt
lt/operationgt lt/bindinggt ltservice
name"CurrencyExchangeService"gt
ltdocumentationgtReturns the exchange rate between
the two currencieslt/documentationgt ltport
name"CurrencyExchangePort" binding"tnsCurrencyE
xchangeBinding"gt ltsoapaddress
location"http//services.xmethods.net80/soap"/gt
lt/portgt lt/servicegt lt/definitionsgt
61
The Two Layers of WSDL
  • The service definition layer describes abstract
    properties
  • data types
  • message types
  • operations
  • services
  • The binding layer describes concrete properties
    (using SOAP, HTTP, MIME)
  • protocols
  • data formats

62
More on the Binding Layer
  • WSDL defines services as collections of network
    endpoints or ports
  • Endpoints are defined by binding a concrete
    network protocol and a concrete message format to
    abstract operations and messages
  • In theory, WSDL can describe any endpoint
    regardless of the underlying network protocol or
    message format
  • In practice, WSDL is used with SOAP/HTTP/MIME

63
The Elements of WSDL Documents
  • Types containing XML Schema element and type
    definitions
  • Message an abstract typed definition of the
    data being communicated
  • Operation an abstract description of an action
    supported by the service
  • Port Type an abstract set of operations
    supported by one or more endpoints
  • Binding a concrete communication protocol and
    data format specification for a particular port
    type
  • Port a single endpoint defined as a combination
    of a binding and a network address
  • Service a collection of named ports, each
    associated with a binding and a network address

64
The Structure of a WSDL Document
  • ltdefinitiongt
  • lttypesgt
  • definition of types.
  • lt/typesgt
  • ltmessagesgt
  • definition of a message
  • lt/messagegt
  • ltport typegt
  • definition of a port
  • lt/port typegt
  • ltbindinggt
  • definition of a binding
  • lt/bindinggt
  • lt/definitiongt

ltdefinitiongt
lttypesgt
ltmessagesgt
ltportTypegt
ltbindinggt
65
Example
  • lt?xml version"1.0" encoding"UTF-8"?gtltdefinition
    s name"HelloService" targetNamespace"http//w
    ww.hello.com/wsdl/HelloService.wsdl"
    xmlns"http//schemas.xmlsoap.org/wsdl/"
    xmlnssoap"http//schemas.xmlsoap.org/wsdl/soap/"
    xmlnstns"http//www.hello.com/wsdl/HelloServ
    ice.wsdl" xmlnsxsd"http//www.w3.org/2001/XML
    Schema"gt

General and specific namespaces
66
Types
  • The lttypesgt element defines the data types that
    are used by the Web service
  • For maximum interoperability, WSDL uses XML
    Schema syntax to define data types

67
Messages
  • The ltmessagegt element defines the data elements
    of an operation
  • Each message can consist of one or more parts
  • These parts are analogous to the parameters of a
    function call in Java

68
Example
ltmessage name"SayHelloRequest"gt ltpart
name"firstName" type"xsdstring"/gtlt/messagegtltm
essage name"SayHelloResponse"gt ltpart
name"greeting" type"xsdstring"/gtlt/messagegt
String sayHello(String firstName)
69
Port Types
  • The ltportTypegt element is the most important WSDL
    element
  • The ltportTypegt element is similar to a class in
    Java
  • It defines the Web service, the operations that
    can be performed, and the messages that are
    involved

70
Example
ltportType name"Hello_PortType"gt ltoperation
name"sayHello"gt ltinput message"tnsSayHell
oRequest"/gt ltoutput message"tnsSayHelloRes
ponse"/gt lt/operationgtlt/portTypegt
public interface HelloService public String
sayHello(String firstName)
71
Operation Types
  • We divide operations to four types
  • One-way the operation can receive a message but
    will not return a response (the operation
    includes only input)
  • Request-response the operation can receive a
    request and will return a response (the operation
    includes input and output)
  • Solicit-response the operation can send a
    request and will wait for a response (the
    operation includes output and input)
  • Notification the operation can send a message
    but will not wait for a response (the operation
    includes only output)

72
Binding Using SOAP
  • The SOAP ltbindinggt element defines the details of
    the message format and protocol for each port
  • The transport attribute defines the SOAP protocol
    to use (e.g., HTTP, FTP, SMTP)
  • The style attribute of the binding can be either
    RPC (Remote Procedure Call) or document (document
    is the default)

73
RPC vs. Document
  • RPC style indicates that the messages contain
    parameters and return values
  • Document style indicates that the messages
    contain document(s)
  • Differently from document style
  • In RPC, we need to clearly separate the arguments
    from each other
  • In RPC, the order of parameters is important

74
The SOAP Binding in WSDL
  • Selects document or rpc style
  • Selects HTTP/SMTP/ protocol
  • Selects encoding (typically, the SOAP encoding)
  • Places messages parts in header or body parts of
    the envelope

75
  • ltbinding name"Hello_Binding" type"tnsHello_Port
    Type"gt
  • ltsoapbinding style"rpc transport"http//sch
    emas.xmlsoap.org/soap/http"/gt
  • ltoperation name"sayHello"gt
    ltsoapoperation soapAction"sayHello"/gt
    ltinputgt ltsoapbody
    encodingStyle"http//schemas.xmlsoap.org/soap/enc
    oding/" namespace"urnexampl
    eshelloservice" use"encoded"/gt
    lt/inputgt ltoutputgt
    ltsoapbody encodingStyle"http//schemas.xmlsoap.o
    rg/soap/encoding/"
    namespace"urnexampleshelloservice"
    use"encoded"/gt lt/outputgt
  • lt/operationgt
  • lt/bindinggt

76
A Service Description in WSDL(defining an
endpoint)
ltservice name"Hello_Service"gt
ltdocumentationgtWSDL File for HelloServicelt/documen
tationgt ltport binding"tnsHello_Binding"
name"Hello_Port"gt ltsoapaddress
location"http//pita8080/soap/servlet/myService"
/gt lt/portgt lt/servicegt lt/definitionsgt
The location attribute associates the binding
with a URL
77
Recall Currency Exchange Example
  • POST http//services.xmethods.net80/soap
    HTTP/1.0
  • Content-Type text/xml
  • Content-Length 485
  • SOAPAction ""
  • ltSOAP-ENVEnvelope xmlnsSOAP-ENV"http//schemas.
    xmlsoap.org/soap/envelope/" xmlnsxsi"http//www.
    w3.org/1999/XMLSchema-instance"
    xmlnsxsd"http//www.w3.org/1999/XMLSchema"gt
  • ltSOAP-ENVBodygt
  • ltns1getRate xmlnsns1"urnxmethods-CurrencyExcha
    nge" SOAP-ENVencodingStyle"http//schemas.xmlsoa
    p.org/soap/encoding/"gt
  • ltcountry1 xsitype"xsdstring"gtUnited
    Stateslt/country1gt
  • ltcountry2 xsitype"xsdstring"gtIsraellt/country2gt
  • lt/ns1getRategtlt/SOAP-ENVBodygtlt/SOAP-ENVEnvelopegt

78
CurrencyExchange's WSDL
  • Next is the WSDL for this service
  • Note that it has to describe
  • URL
  • URI
  • Method Name
  • Method Namespace
  • Parameter Names
  • Parameter Types
  • Encoding of Parameters

79
lt?xml version"1.0"?gt ltdefinitions
name"CurrencyExchangeService" targetNamespace"ht
tp//www.xmethods.net/sd/CurrencyExchangeService.w
sdl" xmlnstns"http//www.xmethods.net/sd/Currenc
yExchangeService.wsdl" xmlnsxsd"http//www.w3.or
g/2001/XMLSchema" xmlnssoap"http//schemas.xmlso
ap.org/wsdl/soap/" xmlns"http//schemas.xmlsoap.o
rg/wsdl/"gt ltmessage name"getRateRequest"gt ltpar
t name"country1" type"xsdstring"/gt ltpart
name"country2" type"xsdstring"/gt lt/messagegt lt
message name"getRateResponse"gt ltpart
name"Result" type"xsdfloat"/gt lt/messagegt
80
ltportType name"CurrencyExchangePortType"gt
ltoperation name"getRate"gt ltinput
message"tnsgetRateRequest" /gt ltoutput
message"tnsgetRateResponse" /gt
lt/operationgt lt/portTypegt ltbinding
name"CurrencyExchangeBinding"
type"tnsCurrencyExchangePortType"gt
ltsoapbinding style"rpc"
transport"http//schemas.xmlsoap.org/soap/http"/gt
ltoperation name"getRate"gt ltsoapoperation
soapAction""/gt ltinput gt ltsoapbody
use"encoded" namespace"urnxmethods-CurrencyExc
hange" encodingStyle"http//schemas.xmlsoap.org/
soap/encoding/"/gt lt/inputgt
81
ltoutput gt ltsoapbody use"encoded"
namespace"urnxmethods-CurrencyExchange"
encodingStyle"http//schemas.xmlsoap.org/soap/en
coding/"/gt lt/outputgt lt/operationgt lt/bindinggt lt
service name"CurrencyExchangeService"gt
ltdocumentationgtReturns the exchange rate
lt/documentationgt ltport name"CurrencyExchangePort
" binding"tnsCurrencyExchangeBinding"gt ltsoap
address location"http//services.xmethods.n
et80/soap"/gt lt/portgt lt/servicegtlt/definitionsgt
82
UDDI Universal Description, Discovery and
Integration
83
A Telephone Book
  • How can you find a Web service?
  • How can you register your Web service so that
    others will find it?
  • UDDI is a standard for publishing and finding Web
    services
  • Think of UDDI as a telephone book

84
How Does UDDI Work?
UDDI Business Registry
Service Type Registrations
BusinessRegistrations
UDDI assigns a universally unique identifier
(UUID) to each registry record
85
"Types" of Pages
  • White Pages
  • Basic contact information, business name,
    address, etc.
  • Allow others to find you based on your
    identification
  • Yellow Pages
  • Describe Web services by category
  • Allow others to find you by category (e.g., car
    sales)
  • Green Pages
  • Technical information about supported methods of
    Web services

86
UDDI Data Model
87
UDDI Structure
  • businessEntity - The top-level XML element
    (includes support for "yellow pages" taxonomies)
  • businessService - contains descriptive business
    service information about a group of related
    technical services, including
  • the group name
  • a brief description
  • technical service-description information
  • service properties
  • service leasing details
  • category information

88
UDDI Structure
  • bindingTemplate - contains data relevant for
    applications that need to invoke or bind to a
    specific Web Service
  • tModel - Descriptions of specifications
    (protocols, formats, etc.) for Web services or
    taxonomies
  • its role is to represent the technical
    specification of the Web service, making it
    easier for Web-service consumers to find Web
    services that are compatible with a particular
    technical specification

89
Key Entities Description
Bindings contain references to tModels. These
references declare the interface specifications
for a service.
0..n
0..n
0..n
90
Key Entities Example
91
Categorizing Entities
92
UDDI Business Registry (UBR), Public Cloud
  • Nodes contain all UDDI information
  • Nodes are synchronized, so they retain the same
    data
  • You can query any node
  • You can add UDDI information to a node, and it
    will be replicated to all others

93
Registry Nodes Operation
  • Peer-operator nodes
  • A business can register with any node
  • Registrations replicated on a daily basis
  • Operates like DNS logically centralized,
    physically distributed

94
Interacting with the UDDI
  • UDDI is itself a Web service!!!
  • Interaction is via SOAP messages
  • The JAXR package defines a standard way to
    interact with registries (can work with other
    types of registries too, e.g., ebXML)
  • Two types of interaction
  • Inquiry Does not need authentification
  • Publish Needs authentification
  • Here is a Web interface for a UBR node

95
JAXR
  • Java API used to access registries that conform
    to standards, such as UDDI
  • Part of Java WSDP

Taken from http//developer.java.sun.com/developer
/technicalArticles/WebServices/WSPack/
96
UDDI API
  • Inquiry API
  • Publishing API
  • find_business
  • find_service
  • find_binding
  • find_tmodel
  • save_business
  • save_service
  • save_binding
  • save_tmodel
  • delete_business
  • delete_service
  • delete_binding
  • delete_tmodel
  • get_businessDetail
  • get_serviceDetail
  • get_bindingDetail
  • get_tmodelDetail
  • get_authtoken
  • discard_authtoken
Write a Comment
User Comments (0)
About PowerShow.com