2. Outlines
What is a Web Service?
Why do we need Web Services?
Types
SOAP vs REST
A Simple Example of SOAP Web Service
WSDL
Web Service Client Example
Queries
3. What is a Web Service ?
A very simple definition is "a service made available over
the web".
The difference between a standard website and a web
service is this: a website is meant for human consumption, while
a web service is meant for machine (or code)
consumption.
Web services are XML-based information exchange systems
that use the Internet for direct application-to-application
interaction. These systems can include programs, objects,
messages, or documents.
4. Why do we need
Web Services ?
A Web service is a unit of managed code that can be remotely invoked
using HTTP, that is, it can be activated using HTTP requests. So, Web
Services allows you to expose the functionality of your existing code over
the network. Once it is exposed on the network, other application can
use the functionality of your program.
Web Services allows different applications to talk to each other and
share data and services among themselves. Other applications can also
use the services of the web services. For example VB or .NET application
can talk to java web services and vice versa. So, Web services is used to
make the application platform and technology independent.
Reuse already developed(old) functionality into new software.
5. Types of Web Services
Simple Object Access Protocol (SOAP)
Representational State Transfer(REST)
In Java we have mainly two types of Web Services :
6. Types Of Web Services
Simple Object Access Protocol (SOAP)
is a standard protocol
specification for message exchange based on XML.
Communication between the web service and client happens using XML messages.
SOAP defines the rules for communication like
what are all the tags that should be used in XML and their meaning.
7. Example of SOAP Web
Service
System Requirements:
Java (latest version)
Eclipse (For J2EE developer)
Apache Tomcat (latest version)
8. Steps for creating web services in eclipse
1. Create new dynamic web project and name it "WebServiceDemo".
9. 2.Create a java file with name ShowProfile and write following code.
12. 5.Click on next , wsdl will be created on WebContent folder.
13. 6.Press finish (You are done with the web service , now you have
Wsdl file which is used to consume web service or say creating a
Client for your web service. )
Before creating the client lets see how the wsdl looks like and what is wsdl ?
15. What is wsdl ?
WSDL stands for Web Services Description Language
WSDL is a language for describing how to interface with XML-based services.
WSDL is an integral part of UDDI, an XML-based worldwide business registry.
WSDL is the language that UDDI uses.
WSDL was developed jointly by Microsoft and IBM.
WSDL is pronounced as 'wiz-dull' and spelled out as 'W-S-D-L'
16. Definition: element must be the root element of all WSDL documents.
It defines the name of the web service,
declares multiple namespaces used throughout the remainder of the document,
and contains all the service elements described here.
Data types: the data types - in the form of XML
schemas or possibly some other mechanism - to be used in the messages
Message: an abstract definition of the data,
in the form of a message presented either as an
entire document or as arguments to be mapped to a method invocation.
Operation: the abstract definition of the operation for a message,
such as naming a method, message queue, or business process,
that will accept and process the message
Port type : an abstract set of operations mapped to one or more end points,
defining the collection of operations for a binding; the collection of operations,
because it is abstract, can be mapped to multiple transports through various bindings.
Binding: the concrete protocol and data formats
for the operations and messages defined for a particular port type.
Port: a combination of a binding and a network address,
providing the target address of the service communication.
Service: a collection of related end points encompassing
the service definitions in the file; the services map the binding to
the port and include any extensibility definitions.
Following are the elements of WSDL document :
17. The main structure of a WSDL document looks like this:
<definitions>
<types>
definition of types........
</types>
<message>
definition of a message....
</message>
<portType>
<operation>
definition of operation....... <operation>
</portType>
<binding>
definition of a binding....
</binding>
<service>
definition of a service....
</service>
</definitions>
18. Web Service Client
It can also be referred to as a consumer or requester.
There are many methods/tools/web-tools are available for consuming web service.
Web tools to generate java classes for Android/iPhone for e.g :
l Easywsdl (http://easywsdl.com/)
l Wsdl2code (http://www.wsdl2code.com/pages/home.aspx)
Java Plugins to generate java stub for e.g:
lCXF wsdl2java plugin
lJax-ws
lApache axis2
19. Step 1 : Open File -> New -> Other... -> Web Services
-> Web ServiceClient
23. You can see the generated java classes like this :
24. Queries
Q. What about security in webservices ?
Ans :When a Web service exposes private-network data to th
outside world, that data travels through four to seven
separate protocol layers (see: TCP/IP or OSI)
thus introducing potential security vulnerabilities.
Implementing security at a higher layer on the protocol s
the application layer,
For instance — generally provides better protection than
implementation at the lower transport layer,
which provides only HTTPS security.
To implement application-layer security,
enable WS-security (a CXF configuration)
on your Web service. WS-security defines
a new SOAP header which is
capable of carrying various security tokens that systems
a Web service caller's identity and privileges.
25. Q. How to create client from wsdl ?
Ans : There are many tools/web-tools and plugins available to create
client for webservice. Like : Axis2 , JAX-WS