Web Services
Denis Helic
IICM, TU Graz
Web as a database
- The Web we use is full of data
- Book information, opinions, prices, arrival times, misc junk, etc.
- The data is organized around a simple data model: node-link model
- Each node is a data item that has a unique address and a representation
- Representation is e.g. HTML, PDF,... for humans, or e.g XML for programs
- Nodes can be interlinked using their unique addresses
Web as a platform for distributed systems
- The Web is full of services that allow humans and programs to use the Web data
- Service also have unique addresses
- Use a particular representation for data exchange, e.g. XML, SOAP, WSDL
- Follow a particular architecture that defines how services are used
- You combine a number of services to achieve a desired functionality , e.g. you create a distributed system
Types of services (1)
- What is Google search engine?
- It is a service for querying a massive database and getting back a formatted response
- What is a Web application?
- It is a service offering a specific functionality and getting back a formatted response
- What is a Web site?
- It is a service offering specific information in a specific format
Types of services (2)
- All these services are for users
- However, we are interested in services for programmers
- Such services provide an API
- Programmers use the API, unique addresses, representations of services
- Programmers follow the arch. style to integrate and combine services to achieve a desired functionality
- We will call this part of the Web: the programmable Web
Kind of Things on the Programmable Web
- There exist numerous approaches to web services in all areas
- The programmable Web is based on HTTP and XML for represenation
- Some parts serve HTML, JSON, plain text, binary documents, but most parts use XML
- The only agreement is HTTP - if you do not use HTTP you are not on the Web
- All other things, representations, addresses, APIs differ
- We need a classification!
Classification based on architectural design
- The only common thing: HTTP
- HTTP is a document-based protocol in which a client puts a document in an envelope and sends it to the server
- The server answers by putting a response document into an envelope and sending it to the client
Method information (1)
- Question: how the client conveys its intention to the server?
- How does a server know a certain request is a request to retrieve some data?
- Instead of a request to delete the same data?
- Why should the server do this instead of doing that
- This information is called method information
Method information (2)
- First alternative
- Convey method information by putting it in the HTTP method
- GET, DELETE, PUT, POST
- Semantics is clear
- It is standardized
Method information (3)
- Second alternative: Flickr services
- http://www.flickr.com/services/rest?method=flickr.photos.search&tags=penguin
- http://www.flickr.com/services/rest?method=flickr.photos.addTags&...
- http://www.flickr.com/services/rest?method=flickr.photos.deleteComment&...
- Method information in method query variable, all methods use GET (although some change the data)
Method information (3)
- Third alternative: SOAP and WSDL
- Method information in the SOAP message as defined by WSDL
wsdl_uri = 'http://api.google.com/GoogleSearch.wsdl'
driver = SOAP.create_rpc_driver(wsdl_uri)
result_set = driver.doGoogleSearch(...)
Method information (4)
POST search/beta2 HTTP/1.1
...
<soap:Envelope>
<soap:Body>
<gs:doGoogleSearch>
<q>REST</q>
</gs:doGoogleSearch>
</soap:Body>
</soap:Envelope>
Method information (5)
<operation name="doGoogleSearch">
<input message="typens:doGoogleSearch" />
<output message="typens:doGoogleSearchResponse" />
</operation>
- Method infromation defined in WSDL and used in SOAP and via SOAP-framework in the code
- HTTP method is always POST
Scoping information (1)
- Question: How the client tells the server on which data to operate?
- E.g. the server knows that the client wants to delete some data, but which data is it?
- Why should server operate on this data instead of that data?
- This information is called scoping information
Scoping information (2)
- First alternative: as query variables in URL
- http://www.google.com/search?q=REST
- Scoping information is search?q=REST
- Method information is in GET
Scoping information (3)
- Another example Flickr
- Most of the query variables are scoping information
- tags=penguin
- Recollect that Flickr also includes method information in query variables
- Thus, URL contains a method and a number of arguments to that method in the sense of programming languages
Scoping information (4)
- Second alternative: scoping information in the body of a SOAP message
POST search/beta2 HTTP/1.1
...
<soap:Envelope>
<soap:Body>
<gs:doGoogleSearch>
<q>REST</q>
</gs:doGoogleSearch>
</soap:Body>
</soap:Envelope>
Competing Architectures
- RESTful, Resource-Oriented Architectures
- RPC-Style Architectures
- REST-RPC Hybrid Architectures
RESTful, Resource-Oriented Architectures
- Method information goes into HTTP methods
- Scoping information goes into URL
- More on this architectural style in the next lecture
RPC-Style Architectures (1)
- RPC - Remote Procedure Call
- An RPC style service recieves an envelope full of data from the client
- The service answers with a similar envelope again full of data to the client
- Both method and scoping information are inside of the envelope
- HTTP methods typically POST but sometimes also GET
RPC-Style Architectures (2)
- The best example of the envelope format is SOAP
- There exist other envelope formats like XML-RPC
- Every RPC-style service defines a completely new vocabulary
- e.g. the way how method information and scoping information are represented
- You need another language to define the representation: e.g. WSDL
RPC-Style Architectures (3)
<methodCall>
<methodName>lookupUPC</methodName>
<params>
<gs:param>
<value>
<string>0920985</string>
</value>
</gs:param>
</params>
</methodCall>
RPC-Style Architectures (4)
- XML documents change depending on method and parameters
- Very similar with SOAP (recollect Google example)
- Of course, format is different but the design is the same
- SOAP is used almost exclusively in such an RPC way
REST-RPC Hybrid Architectures (1)
- Services somewhere between RESTful and RPC services
- http://www.flickr.com/services/rest?method=flickr.photos.search&tags=penguin
- Both method and scoping information is in URL
- HTTP is used as an envelope format
REST-RPC Hybrid Architectures (2)
GET services/rest?method=flickr.photos.search&tags=penguin HTTP/1.1
Host: www.flickr.com
- Another prominent example of this style is del.icio.us
Big Web Services
- When people think about Web Services they typically think about RPC-style services
- In particular they think about SOAP/WSDL representation of this style (Big Web Services)
- Vendors sell this as a completly new technology or acrhitecture
- But, RPC is there for more than 30 years
- e.g. CORBA, COM, ...
Sample SOAP service (1)
- The service prints out the string it recieves (echo)
public class EchoService {
public String echo(String msg) {
return msg;
}
}
Sample SOAP service (2)
- Invoking the service using HTTP GET
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Body>
<echo>
<msg>Hello World!</msg>
</echo>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
Sample SOAP service (3)
- Very simple formatting
- echo element is the method information
- msg subelement is the scoping information
- The service guesses the proper datatype conversions
- In this case very simple because the argument and the return value are simple strings
Sample SOAP service (4)
- Response from the service might look like this (most of the namaspaces are left out)
<soapenv:Envelope>
<soapenv:Body>
<ns1:echo>
<ns1:arg0 xsi:type="soapenc:string"
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">
Hello World!
</ns1:arg0>
</ns1:echo>
</soapenv:Body>
</soapenv:Envelope>
Sample SOAP service (5)
- Additionally, since there is a new vocabulary you need a WSDL
- Even this simple example shows how much overhead is there
- Of course, there are frameworks which create WSDL and SOAP for you
- Still there is processing overhead
SOAP/WSDL Frameworks (1)
- Frameworks provide abstractions of SOAP and WSDL!
- Basically, they allow you to do RPC transparently
- You do not even need to know about SOAP or WSDL
- Frameworks process SOAP and WSDL for you
SOAP and WSDL in Axis (1)
- Java2WSDL tool creates automatically WSDL from Java interfaces
- It creates descriptions of all public methods
- It creates proper datatypes
- It needs to be able to access these datatypes Java classes
- The classes should be JavaBeans
SOAP and WSDL in Axis (1)
- WSDL2Java tool creates Java classes from WSDL descriptions
- Client side
- A Java interface which coresponds to the operations defined in WSDL
- For echo service this would be Echo interface with a single public method
SOAP and WSDL in Axis (2)
- A so-called stub, which is the implementation of the generated interface
- It uses Axis API (e.g., Service, Call) and SOAP to communicate with the service
- A ServiceLocator class which retrieves instances of the generated interface
- Basically it is an Abstract Factory
SOAP and WSDL in Axis (3)
- Server side
- An empty implementation of the generated interface
- You should modify this empty implementation
- Forward the calls to the proper methods of your implementation
Axis - An Example (1)
- PersonDAO interface from the Publication Database
- Basically, we want to offer the access to the database through a service
- The usual way of providing services
- I.e., publishing already existing functionality as Web services
Axis - An Example (2)
....
public void storePerson(Person person);
public Iterator readAllPersons();
public Person readPersonWithId(int id);
....
Axis - An Example (6)
- PersonDAOStub
- Implemets PersonDAO interface and hides the SOAP from the client
public java.lang.Object readAllPersons()
throws java.rmi.RemoteException {
...
org.apache.axis.client.Call _call = createCall();
_call.setOperation(_operations[1]);
_call.setUseSOAPAction(true);
_call.setSOAPActionURI("");
_call.setSOAPVersion(org.apache.axis.soap.SOAPConstants.SOAP11_CONSTANTS);
...
Axis - An Example (7)
...
_call.setOperationName(
new javax.xml.namespace.QName(
"urn:coronet.iicm.edu/persondao",
"readAllPersons"));
setRequestHeaders(_call);
setAttachments(_call);
java.lang.Object _resp =
_call.invoke(new java.lang.Object[] {});
...
Axis - An Example (8)
- Service side
- PersonDAOImplementation
...
public edu.iicm.publication.db.ws.Person
readPersonWithId(int in0)
throws java.rmi.RemoteException {
edu.iicm.publication.db.PersonDAO dao =
DAOFactory.createPersonDAO();
...
Axis - An Example (9)
...
edu.iicm.publication.Person person =
dao.readPersonWithId(in0);
edu.iicm.publication.db.ws.Person out0 =
new edu.iicm.publication.db.ws.Person();
out0.setId(person.getId());
out0.setName(person.getName());
out0.setRole(person.getRole());
return out0;
}
...
Axis - An Example (10)
...
PersonDAOServiceLocator locator = new PersonDAOServiceLocator();
try {
PersonDAO dao = locator.getpersondao();
Person person = new Person();
person.setName(name);
dao.storePerson(person);
log_.debug("Person stored");
...
Problems of SOAP/WSDL (1)
- One problem: it is exclusively used for Remote Procedure Calls
- RPC implies an API
- APIs tend to enforce tight coupling of modules and systems
- We use declarative XML to describe APIs
- This introduces processing overhead
Problems of SOAP/WSDL (2)
- APIs and there definitions in some language e.g. WSDL introduce new vocabulary
- This vocabulary is different from app to app
- You can not standardize this
- This is a big problem for service integration, in particular for automatic integration
- Each service needs to understands what all other services provide
Problems of SOAP/WSDL (3)
- A bigger problem: it goes against the architecture of the Web
- Where are URLs, links, representations
- Of course, there is HTTP
- But how it is used?
- Only as a transport protocol
Problems of SOAP/WSDL (4)
- In essence the only thing Big Web Services have in common with the Web is HTTP
- There are not WEB services
- Why they use than HTTP at all?
- Because of firewalls!