Post on 08-Jan-2016
description
1
Web ServicesWeb Services
Representation and Management of Data on the
Web
2
"Web services are loosely coupled software components
delivered over Internet standard technologies."
"Web services are loosely coupled software components
delivered over Internet standard technologies."
3
Example Scenario:Get Online Information
Stock Exchange
Stock Broker
Application
Get Stock Price
Get Stock Price
Return Stock
Price
Return Stock
Price
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
Book Store
The Hobbit (5)Price: 20.95
Copies in Stock: 5
Buy The Hobbit (5)
Buy The Hobbit (5)
How Much?
20.95
Buy it
The Hobbit (5)Price: 20.95
Copies in Stock: 4
The Hobbit (5)Price: 25.95
Copies in Stock: 1
The Hobbit (5)Price: 25.95
Copies in Stock: 0
5
Example Scenario:Grid Computation
Grid Computation
Using seamlesslythe combinedresources of many computersthat are connectedto 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
What is the price here?
How can we find this URL?
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
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: Apache’s 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/Group/
17
POST /soap HTTP/1.0SOAPAction: ""Content-Length: 520
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body> <ns1:getRate soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns1="urn:xmethods-CurrencyExchange">
<country1 xsi:type="xsd:string">Euro</country1> <country2 xsi:type="xsd:string">Israel</country2> </ns1:getRate> </soapenv:Body></soapenv:Envelope>
A request to A request to http://services.xmethodshttp://services.xmethods
.net:80/soap.net:80/soap
18
HTTP/1.0 200 OKDate: Sat, 07 May 2005 23:26:21 GMTContent-Length: 492Content-Type: text/xml
<?xml version='1.0' encoding='UTF-8'?>
<soap:Envelope xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:soapenc='http://schemas.xmlsoap.org/soap/encoding/' soap:encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'>
<soap:Body> <n:getRateResponse xmlns:n='urn:xmethods-CurrencyExchange'>
<Result xsi:type='xsd:float'>5.5825</Result> </n:getRateResponse> </soap:Body></soap:Envelope>
The ResponseThe 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
<?xml version="1.0"?><Hello> <sayHelloTo> <name>Lisa</name> </sayHelloTo></Hello>
SOAP Simplification (1)
• Consider the Java interface:
• Suppose that a client wants to call the server's sayHelloTo method
• Could send an XML message:
Name of the Interface
Name of the Method
Name of the Parameter
public interface Hello {
public String sayHelloTo(String name);
}
21
SOAP Simplification (2)
• The Server could respond with:<?xml version="1.0"?><Hello> <sayHelloToResponse> <message>Hello Lisa, How are you?</message> </sayHelloToResponse></Hello>
Name of the Interface
Name of the Method + Response
Returned Value
22
SOAP Intuition
23
Skeleton SOAP Message<?xml version="1.0"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<soap:Header>
... ...
</soap:Header>
<soap:Body>
... ...
<soap:Fault>
... ...
</soap:Fault>
</soap:Body>
</soap:Envelope>
A SOAP envelope must be Associated with this name space
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
25Envelope
Actual Soap Request
<SOAP-ENV:Envelope
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/1999/XMLSchema"> <SOAP-ENV:Header> </SOAP-ENV:Header> <SOAP-ENV:Body> <ns1:sayHelloTo xmlns:ns1="Hello"
SOAP-ENV:encodingStyle="
http://schemas.xmlsoap.org/soap/encoding/"> <name xsi:type="xsd:string">Lisa</name> </ns1:sayHelloTo> </SOAP-ENV:Body>
</SOAP-ENV:Envelope>
26Name Spaces
Actual Soap Request
<SOAP-ENV:Envelope
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/1999/XMLSchema"> <SOAP-ENV:Header> </SOAP-ENV:Header> <SOAP-ENV:Body> <ns1:sayHelloTo xmlns:ns1="Hello"
SOAP-ENV:encodingStyle="
http://schemas.xmlsoap.org/soap/encoding/"> <name xsi:type="xsd:string">Lisa</name> </ns1:sayHelloTo> </SOAP-ENV:Body>
</SOAP-ENV:Envelope>
27
Actual Soap Request
HeaderBody
<SOAP-ENV:Envelope
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/1999/XMLSchema"> <SOAP-ENV:Header> </SOAP-ENV:Header> <SOAP-ENV:Body> <ns1:sayHelloTo xmlns:ns1="Hello"
SOAP-ENV:encodingStyle="
http://schemas.xmlsoap.org/soap/encoding/"> <name xsi:type="xsd:string">Lisa</name> </ns1:sayHelloTo> </SOAP-ENV:Body>
</SOAP-ENV:Envelope>
28
Actual Soap Request
<SOAP-ENV:Envelope
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/1999/XMLSchema"> <SOAP-ENV:Header> </SOAP-ENV:Header> <SOAP-ENV:Body> <ns1:sayHelloTo xmlns:ns1="Hello"
SOAP-ENV:encodingStyle="
http://schemas.xmlsoap.org/soap/encoding/"> <name xsi:type="xsd:string">Lisa</name> </ns1:sayHelloTo> </SOAP-ENV:Body>
</SOAP-ENV:Envelope>
InterfaceInterface MethodMethod ParameterParameter
29Envelope
Actual Soap Response<SOAP-ENV:Envelope
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/1999/XMLSchema"> <SOAP-ENV:Body> <ns1:sayHelloToResponse xmlns:ns1="Hello" SOAP-ENV:encodingStyle="
http://schemas.xmlsoap.org/soap/encoding/"> <return xsi:type="xsd:string">
Hello Lisa, How are you doing?
</return> </ns1:sayHelloToResponse> </SOAP-ENV:Body>
</SOAP-ENV:Envelope>
30
Actual Soap Response
Body
<SOAP-ENV:Envelope
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/1999/XMLSchema"> <SOAP-ENV:Body> <ns1:sayHelloToResponse xmlns:ns1="Hello" SOAP-ENV:encodingStyle="
http://schemas.xmlsoap.org/soap/encoding/"> <return xsi:type="xsd:string">
Hello Lisa, How are you doing?
</return> </ns1:sayHelloToResponse> </SOAP-ENV:Body>
</SOAP-ENV:Envelope>
31
Actual Soap Response<SOAP-ENV:Envelope
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/1999/XMLSchema"> <SOAP-ENV:Body> <ns1:sayHelloToResponse xmlns:ns1="Hello" SOAP-ENV:encodingStyle="
http://schemas.xmlsoap.org/soap/encoding/"> <return xsi:type="xsd:string">
Hello Lisa, How are you doing?
</return> </ns1:sayHelloToResponse> </SOAP-ENV:Body>
</SOAP-ENV:Envelope>
MethodMethod InterfaceInterface Returned ValueReturned Value
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:
<SOAP-ENV:Header> <t:Transaction xmlns:t="some-URI"
SOAP-ENV:mustUnderstand="1">5</t:Transaction>
</SOAP-ENV:Header>• 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
• <faultcode> : A code for identifying the fault• <faultstring> : A human readable
explanation of the fault• <faultactor> : Information about who
caused the fault • <detail> : 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
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"> <SOAP-ENV:Body> <SOAP-ENV:Fault> <faultcode>SOAP-ENV:Server</faultcode> <faultstring>Server Error</faultstring> <detail> <e:myfaultdetails xmlns:e="Hello"> <message> Sorry, I cannot say hello on Tuesday. </message> <errorcode>1001</errorcode> </e:myfaultdetails> </detail> </SOAP-ENV:Fault> </SOAP-ENV:Body></SOAP-ENV:Envelope>
38
SOAP Error Response for Header Error
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"> <SOAP-ENV:Body> <SOAP-ENV:Fault> <faultcode>SOAP-ENV:MustUnderstand</faultcode> <faultstring>SOAP Must Understand Error</faultstring> </SOAP-ENV:Fault> </SOAP-ENV:Body></SOAP-ENV:Envelope>
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 HTTPPOST http://www.Hello.com/HelloApplication HTTP/1.0
Content-Type: text/xml; charset=UTF-8 Content-Length: 587
SOAPAction: urn:helloApp
<SOAP-ENV:Envelope …
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 HTTPHTTP/1.0 200 OK
Content-Type: text/xml; charset=UTF-8 Content-Length: 615
<SOAP-ENV:Envelope …
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.net:80/soap HTTP/1.0
Content-Type: text/xml
Content-Length: 485
SOAPAction: ""
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance" xmlns:xsd="http://www.w3.org/1999/XMLSchema">
<SOAP-ENV:Body>
<ns1:getRate xmlns:ns1="urn:xmethods-CurrencyExchange" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<country1 xsi:type="xsd:string">United States</country1>
<country2 xsi:type="xsd:string">Israel</country2>
</ns1:getRate>
</SOAP-ENV:Body></SOAP-ENV:Envelope>
45
HTTP/1.0 200 OK
Content-Type: text/xml
<?xml version='1.0' encoding='UTF-8'?>
<soap:Envelope xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/' xmlns:xsi='http://www.w3.org/1999/XMLSchema-instance' xmlns:xsd='http://www.w3.org/1999/XMLSchema' xmlns:soapenc='http://schemas.xmlsoap.org/soap/encoding/' soap:encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'>
<soap:Body><n:getRateResponse
xmlns:n='urn:xmethods-CurrencyExchange'>
<Result xsi:type='xsd:float'>4.521</Result>
</n:getRateResponse>
</soap:Body></soap:Envelope>
And Here is the Response
46
Example - Calling Google Spelling<?xml version="1.0" encoding="UTF-8" ?>
<SOAP-ENV:Envelope xmlns:SOAP
ENV=“http://schemas.xmlsoap.org/soap/envelope/”
xmlns:xsi=“http://www.w3.org/1999/XMLSchema-instance”
xmlns:xsd=“http://www.w3.org/1999/XMLSchema”>
<SOAP-ENV:Body>
<ns1:doSpellingSuggestion xmlns:ns1=“urn:GoogleSearch” SOAP- ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<key xsi:type="xsd:string">00000000000000000000000000</key>
<phrase xsi:type="xsd:string">britney speers</phrase>
</ns1:doSpellingSuggestion>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
47
Example - Google Spelling Response<?xml version="1.0" encoding="UTF-8" ?>
<SOAP-ENV:Envelope xmlns:SOAP ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/1999/XMLSchema">
<SOAP-ENV:Body>
<ns1:doSpellingSuggestionResponse xmlns:ns1="urn:GoogleSearch“
SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<return xsi:type="xsd:string">britney spears</return>
</ns1:doSpellingSuggestionResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
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 ExamplePOST /MyRPC HTTP/1.0
Host: www.cs.huji.ac.il
Content-Type: text/xml
Content-length: 181
<?xml version="1.0"?>
<methodCall> <methodName>Hello.sayHelloTo</methodName>
<params>
<param>
<value><string>Lisa</string></value> </param>
</params>
</methodCall>
50
XML-RPC Response ExampleHTTP/1.1 200 OK
Connection: close
Content-Length: 158
Content-Type: text/xml
Date: Sun, 6 Jun 2004 10:33:08 GMT
<?xml version="1.0"?>
<methodResponse>
<params>
<param>
<value><string>Hello Lisa</string></value> </param>
</params>
</methodResponse>
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
<?xml version="1.0"?>
<definitions name="CurrencyExchangeService" targetNamespace="http://www.xmethods.net/sd/CurrencyExchangeService.wsdl" xmlns:tns="http://www.xmethods.net/sd/CurrencyExchangeService.wsdl" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns="http://schemas.xmlsoap.org/wsdl/">
<message name="getRateRequest"> <part name="country1" type="xsd:string"/> <part name="country2" type="xsd:string"/> </message>
<message name="getRateResponse"> <part name="Result" type="xsd:float"/> </message>
<portType name="CurrencyExchangePortType"> <operation name="getRate"> <input message="tns:getRateRequest" name="getRate"/> <output message="tns:getRateResponse" name="getRateResponse"/> </operation></portType>
60
<binding name="CurrencyExchangeBinding" type="tns:CurrencyExchangePortType">
<soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
<operation name="getRate"> <soap:operation soapAction=""/>
<input name="getRate"> <soap:body use="encoded" namespace="urn:xmethods-CurrencyExchange" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/> </input>
<output name="getRateResponse"> <soap:body use="encoded" namespace="urn:xmethods-CurrencyExchange" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/> </output> </operation></binding>
<service name="CurrencyExchangeService"> <documentation>Returns the exchange rate between the two currencies</documentation> <port name="CurrencyExchangePort" binding="tns:CurrencyExchangeBinding"> <soap:address location="http://services.xmethods.net:80/soap"/> </port></service></definitions>
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
<definition><types> definition of types….</types><messages> definition of a message</message><port type> definition of a port</port type><binding> definition of a binding</binding></definition>
<definition>
<types>
<messages>
<portType>
<binding>
65
Example
<?xml version="1.0" encoding="UTF-8"?>
<definitions name="HelloService"
targetNamespace="http://www.hello.com/wsdl/HelloService.wsdl"
xmlns="http://schemas.xmlsoap.org/wsdl/"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:tns="http://www.hello.com/wsdl/HelloService.wsdl"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
General and specific namespacesGeneral and specific namespaces
66
Types
• The <types> 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 <message> 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
<message name="SayHelloRequest">
<part name="firstName" type="xsd:string"/>
</message>
<message name="SayHelloResponse">
<part name="greeting" type="xsd:string"/>
</message>
String sayHello(String firstName)
69
Port Types
• The <portType> element is the most important WSDL element
• The <portType> 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
<portType name="Hello_PortType">
<operation name="sayHello">
<input message="tns:SayHelloRequest"/>
<output message="tns:SayHelloResponse"/>
</operation>
</portType>
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 <binding> 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
<binding name="Hello_Binding" type="tns:Hello_PortType">
<soap:binding style="rpc“ transport="http://schemas.xmlsoap.org/soap/http"/>
<operation name="sayHello">
<soap:operation soapAction="sayHello"/>
<input>
<soap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
namespace="urn:examples:helloservice" use="encoded"/>
</input>
<output>
<soap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
namespace="urn:examples:helloservice" use="encoded"/>
</output>
</operation>
</binding>
76
A Service Description in WSDL(defining an endpoint)
<service name="Hello_Service">
<documentation>WSDL File for HelloService</documentation>
<port binding="tns:Hello_Binding" name="Hello_Port">
<soap:address location="http://pita:8080/soap/servlet/myService"/>
</port>
</service>
</definitions>
The location attribute associates the binding with a URL
The location attribute associates the binding with a URL
77
Recall Currency Exchange Example
POST http://services.xmethods.net:80/soap HTTP/1.0
Content-Type: text/xml
Content-Length: 485
SOAPAction: ""
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance" xmlns:xsd="http://www.w3.org/1999/XMLSchema">
<SOAP-ENV:Body>
<ns1:getRate xmlns:ns1="urn:xmethods-CurrencyExchange" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<country1 xsi:type="xsd:string">United States</country1>
<country2 xsi:type="xsd:string">Israel</country2>
</ns1:getRate></SOAP-ENV:Body></SOAP-ENV:Envelope>
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
<?xml version="1.0"?>
<definitions name="CurrencyExchangeService" targetNamespace="http://www.xmethods.net/sd/CurrencyExchangeService.wsdl" xmlns:tns="http://www.xmethods.net/sd/CurrencyExchangeService.wsdl"
xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns="http://schemas.xmlsoap.org/wsdl/">
<message name="getRateRequest">
<part name="country1" type="xsd:string"/>
<part name="country2" type="xsd:string"/>
</message>
<message name="getRateResponse">
<part name="Result" type="xsd:float"/>
</message>
80
<portType name="CurrencyExchangePortType">
<operation name="getRate">
<input message="tns:getRateRequest" />
<output message="tns:getRateResponse" />
</operation>
</portType>
<binding name="CurrencyExchangeBinding"
type="tns:CurrencyExchangePortType">
<soap:binding style="rpc"
transport="http://schemas.xmlsoap.org/soap/http"/>
<operation name="getRate">
<soap:operation soapAction=""/>
<input > <soap:body use="encoded"
namespace="urn:xmethods-CurrencyExchange"
encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</input>
81
<output >
<soap:body use="encoded"
namespace="urn:xmethods-CurrencyExchange"
encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</output>
</operation>
</binding>
<service name="CurrencyExchangeService">
<documentation>Returns the exchange rate </documentation>
<port name="CurrencyExchangePort"
binding="tns:CurrencyExchangeBinding">
<soap:address
location="http://services.xmethods.net:80/soap"/>
</port>
</service></definitions>
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 TypeRegistrations
BusinessRegistrations
UDDI assigns a universally unique identifier (UUID) to each registry record
Businesses populate the registry withdescriptions of the services they support
Businesses use this data to facilitate easier integration with each other over the Web
Marketplaces, search engines and business apps query the registry to discover services at other companies
Software companies, standards bodies and programmers populate the registry with descriptions of different service specifications
85
"Types" of Pages
• White Pages:White Pages: – Basic contact information, business name, address, etc. – Allow others to find you based on your identification
• Yellow Pages:Yellow Pages:– Describe Web services by category– Allow others to find you by category (e.g., car sales)
• Green Pages:Green Pages:– Technical information about supported methods of Web
services
86
UDDI Data Model
businessKey BA744ED0 . . . 5229C64 name XMethodsdescription Web services resource site contacts Lisa SimpsonbusinessServicesidentifierBagcategoryBag
businessEntity
tModelKey 8609C8 … D01823keyName D-U-N-SkeyValue 08-146-6849
keyedReference
tModelKey 8609C8 … D01823Name dnb-com:D-U-N-SDescription Dun&Bradstreet D-U-N-S NumberoverviewDoc www.uddi.org/taxonomies/ UDDI_Taxonomy_tModels.htm#D-U-N-ScategoryBag
tModel
serviceKey D59211 … 229C64name XMethods Delayed Stock Quotesdescription 20-minute delayed stock quotesbindingTemplatescategoryBag
businessService
bindingTemplate
bindingKey D594A … 229C64description SOAP binding for delayed stock quotes serviceaccessPoint http://services.xmethods.net:80/soaptModelInstanceDetails
tModelKey 0E727D … 229C64Name Xmethods Simple Stock Quotedescription Simple stock quote interfaceoverviewDoc xmethods.net/SimpleStockQuote.wsdlcategoryBag
tModel
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
businessEntitybusinessEntity
Information about the entity whooffers a service
businessServicebusinessService
Descriptive information about a particular family of technicalofferings
bindingTemplatebindingTemplate
Technical information about aservice entry point
tModeltModel
Description of specifications forservices
0..n
0..n
0..n
Bindings contain references to tModels. These references declare the interface specifications for a service.
90
Key Entities Example
businessEntitybusinessEntity
Name: Acme CorpDesc: Purveyors of Fine ProductsURL: www.acme.comContact: Joseph Cohen
businessServicebusinessService
Name: getPriceDesc: Accepts ACME product ID as a string. Returns product priceas a double.
bindingTemplatebindingTemplate
Access Point: http://soap.acme.com/getPriceDesc: SOAP endpoint for the getPrice service.
publisherAssertionpublisherAssertion
From Key: Acme Corp.To Key: Nadir Corp.
tModeltModel
Name: getPriceDesc: WSDL for the getPrice serviceOverview Doc:http://soap.acme.com/getPrice/wsdl
categorycategory
wsdlSpec
identifieridentifier
E1-AA-09-F3
91
Categorizing EntitiesbusinessEntitybusinessEntity
Name: Acme CorpDesc: Purveyors of Fine ProductsURL: www.acme.comContact: Joseph Cohen
businessServicebusinessService
Name: getPriceDesc: Accepts ACME product ID as a string. Returns product priceas a double.
bindingTemplatebindingTemplate
Access Point: http://soap.acme.com/getPriceDesc: SOAP endpoint for the getPrice service.
tModeltModel
Name: getPriceDesc: WSDL for the getPrice serviceOverview Doc:http://soap.acme.com/getPrice/wsdl
categorycategory
Retail
identifieridentifier
DUNS: 123456
categorycategory
Pricing
categorycategory
wsdlSpec
categorycategory
V 1.1
identifieridentifier
E1-AA-09-F3
publisherAssertionpublisherAssertion
From Key: Acme Corp.To Key: Nadir Corp.
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
IBM
Microsoft
HPother
other
queries
UDDI Cloud Service
client
Registry Node
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
• delete_business• delete_service• delete_binding• delete_tmodel
• delete_business• delete_service• delete_binding• delete_tmodel
• find_business• find_service• find_binding• find_tmodel
• find_business• find_service• find_binding• find_tmodel
• get_businessDetail
• get_serviceDetail• get_bindingDetail• get_tmodelDetail
• get_businessDetail
• get_serviceDetail• get_bindingDetail• get_tmodelDetail
• save_business• save_service• save_binding• save_tmodel
• save_business• save_service• save_binding• save_tmodel
• get_authtoken• discard_authtoke
n
• get_authtoken• discard_authtoke
n