WEB SERVICES
Topics
Understand Web Services and its
types
Implement WSDL File
Create a SOAP based web service
Create a RESTful web service
Web Services-Introduction
Why Web Services
Examples of Using Web Services
Web Services
Web Services - SOAP
Web Services - SOAP
Web Services Interaction - SOAP
Relationship between first-generation
specification
UDDI is accessed using SOAP
enables discovery of binds to
WSDL
enables communication between
describes
Web Service
10 Web Services 05/14/2025
Relationship between first-generation
specification
XML defines types and
Schema payload structure for
SOAP
defines types for binds to
WSDL
is accessed using
Enables discovery of
UDDI
11 Web Services 05/14/2025
Web Services - SOAP
SOAP
SOAP Format
Example of SOAP Request
Example of SOAP Response
WSDL
WSDL
Example of WSDL File
Structure of a WSDL
WSDL definition
<types>
….
</types>
abstract
definition
<message>
…
</message>
<portType> or <interface>
….
</portType> or </interface>
concrete
definition
<binding>
….
</binding>
<service>
…
</service>
20 Web Services 05/14/2025
Structure of a WSDL
Definition documents acts as building blocks for a service description:
Abstract + Concrete = Service Definition
Service Definition + Supplementary Definitions = Service Description
Abstract: The description of a Web service interface, independent of implementation
details, is referred to as the abstract. Within a WSDL document, this abstract interface
definition is primarily made up of the interface/porttype and message constructs. It is
further supported by the types construct, which is often classified separately.
Eg: In a component-based architecture, the service interface is often compared to the
Interface Definition. Language (IDL) file used to describe a component interface.
Concrete: Specific location and implementation information about a Web service are the
concrete parts of a WSDL document, as represented by the binding, service, and
endpoint (or port) elements.
21 Web Services 05/14/2025
Service definition to WSDL document
22 Web Services 05/14/2025
WSDL
23 Web Services 05/14/2025
WSDL-Abstract interface/portType definition
Individual Web service interfaces are represented by WSDL interface/portType elements.
These constructs contain a group of logically related operations. In a component-based
architecture, a WSDL interface/portType is comparable to a component interface. An
operation is therefore the equivalent of a component method, as it represents a single
action or function.
Eg:
<definitions>
<interface or portType name="Catalog">
<operation name="GetBook">
…
</operation>
</interface or portType >
</definitions>
24 Web Services 05/14/2025
WSDL-Abstract interface/portType definition
A typical operation element consists of a group of related input and output messages.
The execution of an operation requires the transmission or exchange of these messages
between the service requestor and the service provider.
Operation messages are represented by message constructs that are declared separately
under the definitions element. The message names then are referenced in the operation’s
input or output child elements.
Eg:
<definitions>
….
<message name="BookInfo">
…
</message>
<interface or portType name="Catalog">
<operation name="GetBook">
<input name="Msg1" message="BookInfo" />
</operation>
..
</definitions>
25 Web Services 05/14/2025
WSDL- message
A message element can contain one or more input or output parameters that belong to
an operation.
Each part element defines one such parameter. It provides a name/ value set, along with
an associated data type.
In a component-based architecture, a WSDL part is the equivalent of an input or output
parameter (or a return value) of a component method.
Eg:
<definitions>
<message name="BookInfo">
<part name="title* type>
Field Guide
</part>
<part name="author* type="xs:string">
Mr. Teshale
</part>
</message>
</definition
26 Web Services 05/14/2025
WSDL-Abstract
Here’s a brief summary of the fundamental constructs that can be assembled to establish
abstract interface definition:
* interfaces represent service interfaces, and can contain multiple operations
* operations represent a Web service function, and can reference multiple messages
* messages represent collections of input or output parameters, and can contain multiple parts
* parts represent either incoming or outgoing operation parameter data
27 Web Services 05/14/2025
Web Services - SOAP
28 Web Services 05/14/2025
SOAP
29 Web Services 05/14/2025
Web Services - SOAP
30 Web Services 05/14/2025
SOAP Format
31 Web Services 05/14/2025
Envelope construct
<env:Envelope xmlns:env="http: //www.w3.org/2003/05/soap-envelope">
<env:Header>
…
</env:Header>
<env: Body>
…
</env: Body>
</env:Envelope>
32 Web Services 05/14/2025
Header construct
<env:Envelope xmlns;env="http://www.w3.org/2003/05/soap-envelope">
<env:Header>
<n:shipping >
UPS
</n:shipping>
</env:Header>
<env:Body>
…
</env:Body>
</env:Envelope>
33 Web Services 05/14/2025
Body construct
<env:Envelope xmina:enva"http; //www.w3 .org/2003/05/soap-envelope”>
<env:Header>
…
</env:Header>
<env: Body>
<x:Book xmlns:x="http://www. examples.ws/">
<x:Title>
Service-Oriented Architecture
A Field Guide to Integrating XML
and Web services
</x:Title>
</x:Book>
</env:Body>
</env:Envelope>
34 Web Services 05/14/2025
fault construct
<env:Envelope xmlns:env="http: //www.w3 .org/2003/05/soap-envelope">
<env:Body>
<env: Fault>
<env:Code>
<env:Value>
env:VersionMismatch
</env:Value>
</env:Code>
<env: Reason>
<env:Text xml:lang="en">
versions do not match
</env:Text>
</env:Reason>
</env:Fault>
</env:Body>
</env:Envelope>
35 Web Services 05/14/2025
Example of SOAP Request
<?xml version="1.0"?>
<soap: Envelope
xmlns:soap="http://mm.w3.org/20@1/12/soap-envelope”
soap:encodingStyle="http://www.w3. org/2001/12/soap-encoding">
<soap:Body xmlns:s="http://ww. stock_brokerage.org/stock">
<s:GetStockPrice>
<s:StockName>Oracle</s:StockName>
</s:GetStockPrice>
</soap:Body>
</soap:Envelope>
36 Web Services 05/14/2025
Example of SOAP Response
<?xml _version="1.0”?>
<soap:Envelope
xmlns : soap="http://www.w3.0rg/2001/12/soap-envelope”
soap:encodingStyle="http: //m.w3.org/2001/12/soap-encoding”>
<soap:Body xmlns:s="http://www.Stock_brokerage.org/stock">
<s:GetStockPriceResponse>
<s:Price>100.50</s:Price>
</s:GetStockPriceResponse>
</soap:Body>
</soap:Envelope>
37 Web Services 05/14/2025
A SOAP message body defined within the WSDL message construct
38 Web Services 05/14/2025
SOAP over HTTP
HTTP is the most common transport used to exchange SOAP messages.
SOAP-over-HTTP is a natural match with SOAP's RPC (request-response)
conventions because HTTP is a request-response-based protocol.
The SOAP request message is posted to the HTTP server with the HTTP
request, and the server returns the SOAP response message in the
HTTP response
HTTP request and HTTP response messages that contain a SOAP
message
39 Web Services 05/14/2025
SOAP over HTTP
HTTP request containing a SOAP message :
POST /StockQuote HTTP/1.1
Content-Type: text/xml
Content-Length: nnnn
SOAPAction: "urn:StockQuote#GetQuote"
<s:Envelope xmlns:s="http://www.w3.org/2001/06/soap-envelope">
...
</s:Envelope>
HTTP response containing a SOAP message :
HTTP/1.1 200 OK
Content-Type: text/xml
Content-Length: nnnn
<s:Envelope xmlns:s="http://www.w3.org/2001/06/soap-envelope">
...
</s:Envelope>
40 Web Services 05/14/2025
Service provider consisting of message processing and business
logic
41 Web Services 05/14/2025
Revised service provider model now including an endpoint within the message processing logic
42 Web Services 05/14/2025
Apache Axis
43 Web Services 05/14/2025
Web Services Development using SOAP
44 Web Services 05/14/2025
JAX-WS annotations to implement SOAP based
WS
Contract first approach using WSDL( Top down approach/ Reverse engineering)
It is a useful approach in case of generating web service implementation from the
contract/WSDL/interface doc.
Code first approach(bottom up approach/forward engineering)
It is a useful approach in case of legacy applications to expose it as web service.
45 Web Services 05/14/2025
Web service
Implementations
Using annotations:
Annotate class/interface as @Webservice
Eg:
@Webservice
class FinnancialService{
}
Annotating web service operations
@Webservice
class FinnancialService{
@Webmethod
public List<Amount> convertToUSD( ArrayList<AmountInFC> a);
}
Note: Most of the WSDL documents elements and its attributes
values can be replaced by the annotations
46 Web Services 05/14/2025
Publishing Endpoint of the Web
service
import javax.xml.ws.Endpoint;
public class Ep {
public static void main(String args[]){
Endpoint.publish("http://localhost:12345/cal", new Cal());
}
}
Note: Create the java project
47 Web Services 05/14/2025
Generating stubs of the web service us
wsimport
wsimport is used to generate stubs of the web service using its WSDL
Document
Eg:
wsimport options
http://ravindras-macbook-air-10.local:8080/WS51/Cal?wsdl
To get the .java classes
wsimport -keep -s src
http://ravindras-macbook-air-10.local:8080/WS51/Cal?wsdl
wsimport -keep -d abc
http://ravindras-macbook-air-10.local:8080/WS51/Cal?wsdl
wsimport -quit http://ravindras-macbook-air-10.local:8080/WS51/Cal?wsdl
wsimport -s src -p edu.tvti
http://ravindras-macbook-air-10.local:8080/WS51/Cal?wsdl
48 Web Services 05/14/2025
Implementation of Web client
program
Create ja ava project
Generate the stubs using wsimport
Keep the stubs in the java project in the corresponding package
public class WS51Client {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Cal_Service cs= new Cal_Service();
System.out.println(cs.getCalPort().add(40, 400));
System.out.println(cs.getCalPort().hello("Babu"));
}
}
49 Web Services 05/14/2025
Web Services Implementation
50 Web Services 05/14/2025
Web Services Implementation
51 Web Services 05/14/2025
Web Services Implementation
52 Web Services 05/14/2025
Web Services Implementation
53 Web Services 05/14/2025
Web Services Implementation
54 Web Services 05/14/2025
Web Services Implementation
55 Web Services 05/14/2025
Web Services Implementation
56 Web Services 05/14/2025
High level relationship between first and second
generation
Describes the service for
uses uses
UDDI
is accessed using
Describes the service for
SOAP
enables discovery of
binds to uses
BPEL4WS for
xt
o nte str
at es
uses
esc c h e
Provides proto n ag or WSDL
col for Ma E
tra nabl
ns e d
ac is
WS-Coordination tio tri enables communication between
n s bu
f o t ed
r
describes
t
tex
Provides proto co n Provides guaranteed delivery for
col for es
a nag
M
f or Web Services
WS-Transaction
of
bi es
Pr
l i a ov
en ovi
y
li t
re pr
d de
se s e
Im
cu n s
ri t d -t
y govern WS-Reliable
fo o -
r
messaging
WS-Security WS-Policy
es
es
us
us
57 Web Services 05/14/2025
REST Services
58 Web Services 05/14/2025
JAX-RS
59 Web Services 05/14/2025
Restful Services
60 Web Services 05/14/2025
Creating Restful Service
61 Web Services 05/14/2025
Restful Service -web.xml
62 Web Services 05/14/2025
RESTful Service - Java Code
63 Web Services 05/14/2025
Creating Restful Service
64 Web Services 05/14/2025
Restful-client
65 Web Services 05/14/2025
Restful-client
66 Web Services 05/14/2025
QUESTIONS PLEASE