Web Services
Written by Liron Blecher
© Liron Blecher
What is a Web Service
A web service is an interface to a web application that is designed
to be used by programs rather than human users.
A web service receives requests from clients via HTTP. The web
service carries out the request sends back a response via
HTTP.
Both the request and the response are encoded in a format that is
easy for a program to decode. The most common encodings
are XML and JSON.
For modern web services, JSON is typically favored, since it is
simpler and easier than XML to encode/decode. Another
common encoding is CSV (Comma-Separated Values).
2
Web Service Roles
There are three major roles
Service
Registry
2) Discover Logically Centralized directory of services 1) Register
services service
Service Service
Requestor 3) Invoke service Provider
Consumer of the Web Service Provider of the Web
Service
3
Types of Web Services
Web services can be implemented in various ways. The
two most popular methods of implementation are:
• SOAP web services
• RESTful web services
4
SOAP Web Services
SOAP web services use XML messages that follow the
Simple Object Access Protocol (SOAP) standard, an
XML language defining a message architecture and
message formats.
Such systems often contain a machine-readable
description of the operations offered by the service,
written in the Web Services Description Language
(WSDL), an XML language for defining interfaces
syntactically.
In Java EE 6, JAX-WS provides the functionality for
“big” web services.
.net provides provides asmx and WCF as soap
5
RESTful Web Services
RESTful web services (Representational State Transfer) an architecture
style for designing networked applications.
The idea is that, rather than using complex mechanisms such as CORBA,
RPC or SOAP to connect between machines, simple HTTP is used to
make calls between machines.
Developing RESTful web services is inexpensive and thus has a very low
barrier for adoption.
REST is well suited for basic scenarios. RESTful web services better
integrated with HTTP than SOAP-based services are, do not require
XML messages or WSDL service–API definitions.
In Java EE 6, JAX-RS provides the functionality for RESTful web services.
.net provides asp.net Web API as RESTful services and return data back
in JSON format
6
Soap Web Service - Protocol Stack
Role Protocol Description
Responsible for centralizing
Discovery UDDI
services
Responsible for describing the
Description WSDL public interface to a specific web
service
Responsible for encoding messages
XML Messaging SOAP
in common XML format
Responsible for transporting
Transport HTTP/S
messages
7
Soap Web Service - SOAP
What is SOAP?
• Simple Object Access Protocol
• Is a protocol that uses XML messages to perform
RPC (Remote Procedure Calls), meaning, call a
function on another (usually remote) program
• Requests are encoded in XML and send via HTTP
• Responses are encoded in XML and received via
HTTP
8
Soap Web Service - SOAP Message
SOAP Message • Envelope is like a
Envelope wrapper for content
• Header is a optional
Header
element that could
contain control
information
Body
• Body element includes
requests and responses
• Body element can also
include a Fault element
in case of an error
9
Big Web Service - Sample SOAP Request
querying a phonebook
10
Soap Web Service - WSDL
What is WSDL?
Web Services Description Language
Has 6 major elements:
1. Definitions – defines the name of the web service
2. Types – describes all the data types that will be transmitted
3. Message – defines the name of the message that will be
transmitted
4. PortType – defines the operations
5. Binding – defines how the message will be transmitted
6. Service – defines where the service is located
11
SOAP Configuration
Development plan for Service Requestor
1) Find web service via UDDI
2) Retrieve service description file
3) Create XML-RPC or SOAP client
4) Invoke remote service
13
Development plan for Service Provider
1) Create the core functionality
2) Create XML-RPC or SOAP service wrapper
3) Create service description file
4) Deploy service
5) Register new service via UDDI
14
What is RESTful Web Service
A RESTful Web Service is a Web Service that binds the
HTTP methods (GET, POST, DELETE & PUT) to
server methods.
rather than using complex mechanisms such as
CORBA, RPC or SOAP to connect between
machines, simple HTTP is used to make calls
between machines.
In this manner, there is no need to send XML messages
since the basic methods are already defined in the
HTTP protocol.
It is usually used to expose a CRUD (Create, Read,
Update and Delete) functionality of the server.
.
15
REST RESOURCES
Resources are the key abstractions in REST.
They are the remote accessible objects of the
application.
A resource is a unit of identification.
Everything that might be accessed or be manipulated
remotely could be a resource.
http://soacookbook.com/customers •
http://soacookbook.com/customers/1234 •
http://soacookbook.com/orders/456/customer •
http://www.acme.com/phonebook/UserDetails/12345
http://www.acme.com/phonebook/getUserDetails?id=12345 •
http://www.acme.com/phonebook/user12345.xml
RESTful Example
SOAP
Google GeoCoding API
Documentation
https://developers.google.com/maps/documentation/geocoding/ •
Request for XML response
http://maps.googleapis.com/maps/api/geocode/xml?address=1600+Amp •
hitheatre+Parkway,+Mountain+View,+CA&sensor=true
Request for JSON response
http://maps.googleapis.com/maps/api/geocode/json?address=1600+Am •
phitheatre+Parkway,+Mountain+View,+CA&sensor=true