♠ Posted by
Java Tutorials
at
10:17 PM
WEB SERVICE TUTORIAL CONTENT:
1. Web Service tutorial
Web service
is a way of communication that allows interoperability between different
applications on different platforms, for example, a java based application on
Windows can communicate with a .Net
based one on Linux. The communication can be done through a set of XML messages
over HTTP protocol.
Web services are browsers and operating system independent service, which means it can run on any browser without the need of making any changes. Web Services take Web-applications to the Next Level.
The World Wide Web Consortium (W3C) has defined the web services. According to W3C, “Web Services are the message-based design frequently found on the Web and in enterprise software. The Web of Services is based on technologies such as HTTP, XML, SOAP, WSDL, SPARQL, and others.”
Let’s say, you are a java developer and you can publish your functions on internet or lan through java web service so any other developer (lets say .Net developer) can access your function.
Web services are browsers and operating system independent service, which means it can run on any browser without the need of making any changes. Web Services take Web-applications to the Next Level.
The World Wide Web Consortium (W3C) has defined the web services. According to W3C, “Web Services are the message-based design frequently found on the Web and in enterprise software. The Web of Services is based on technologies such as HTTP, XML, SOAP, WSDL, SPARQL, and others.”
Let’s say, you are a java developer and you can publish your functions on internet or lan through java web service so any other developer (lets say .Net developer) can access your function.
2. Why you need to learn web services:
2.8.1.1 Reuse already
developed(old) functionality into new software:
Lets
understand with very simple example.Lets say you are developing a finance
software for a company on java and you have old .net software which manages
salary of employees.So rather then developing new software for employee
part,you can use old software and for other parts like infrastructure you can
develop your own functionalities.
2.8.1.2 Usability :
Web Services
allow the business logic of many different systems to be exposed over the Web.
This gives your applications the freedom to chose the Web Services that they
need. Instead of re-inventing the wheel for each client, you need only include
additional application-specific business logic on the client-side. This allows you
to develop services and/or client-side code using the languages and tools that
you want.
2.8.1.3 Interoperability :
This is the
most important benefit of Web Services. Web Services typically work outside of
private networks, offering developers a non-proprietary route to their
solutions.Web Services also let developers use their preferred programming
languages. In addition, thanks to the use of standards-based communications
methods, Web Services are virtually platform-independent.
2.8.1.4 Loosely Coupled:
Each service
exists independently of the other services that make up the application.
Individual pieces of the application to be modified without impacting unrelated
areas.
2.8.1.5 Ease of Integration:
Data is
isolated between applications creating ’silos’. Web Services act as glue
between these and enable easier communications within and across organisations.
2.8.1.6 Deployability :
Web Services
are deployed over standard Internet technologies. This makes it possible to
deploy Web Services even over the fire wall to servers running on the Internet
on the other side of the globe. Also thanks to the use of proven community
standards, underlying security (such as SSL) is already built-in.
3. Elements in Web services:
3.1 Simple
Object Access Protocol(SOAP):
SOAP is a
protocol specification for exchanging structured information in the
implementation of Web services in computer networks. It relies on XML as its
message format.
3.2 Web
Service Description Language(WSDL):
WSDL stands
for Web Service Description Language. It is an XML file that describes the technical details of how to implement a web service, more specifically the
URI, port, method names, arguments, and data types. Since WSDL is XML, it is both human-readable and machine-consumable, which aids in the ability to call and
bind to services dynamically.
Elements of WSDL are:
Description:
It is the root element of a WSDL 2.0 file. It usually contains a set of name space declarations which are used throughout the WSDL file.
Types:
The WSDL types element describes the data types used by your web service.Data types are usually specified by XML schema. It can be described in any language as long as your web services API supports it.
Elements of WSDL are:
Description:
It is the root element of a WSDL 2.0 file. It usually contains a set of name space declarations which are used throughout the WSDL file.
Types:
The WSDL types element describes the data types used by your web service.Data types are usually specified by XML schema. It can be described in any language as long as your web services API supports it.
Binding:
The WSDL binding element describes how your web service is bound to a protocol. In other words, how your web service is accessible. To be accessible, the web service must be reachable using some network protocol. This is called "binding" the web service to the protocol.
Interface:
The WSDL interface element describes the operations supported by your web service. It is similar to methods in programming language. Client can only call one operation per request.
Service:
It describes the endpoint of your web service. In other words, the address where the web service can be reached.
Endpoint:
The endpoint element describes the address of the web service. The endpoint binding attribute describes what binding element this endpoint uses.i.e. protocol with which you will access web service. The address attribute describes the URI at which you can access the service.
The WSDL binding element describes how your web service is bound to a protocol. In other words, how your web service is accessible. To be accessible, the web service must be reachable using some network protocol. This is called "binding" the web service to the protocol.
Interface:
The WSDL interface element describes the operations supported by your web service. It is similar to methods in programming language. Client can only call one operation per request.
Service:
It describes the endpoint of your web service. In other words, the address where the web service can be reached.
Endpoint:
The endpoint element describes the address of the web service. The endpoint binding attribute describes what binding element this endpoint uses.i.e. protocol with which you will access web service. The address attribute describes the URI at which you can access the service.
Message:
The message element describes the data being exchanged between the Web service providers and consumers.
Sample WSDL file:
The message element describes the data being exchanged between the Web service providers and consumers.
Sample WSDL file:
1.
<?xml version="1.0" encoding="UTF-8"?>
2.
<wsdl:definitions targetNamespace="http://webservices.thinkjava.net” xmlns:apachesoap="http://xml.apache.org/xml-soap" xmlns:impl="http://webservices. thinkjava.net" xmlns:intf="http://webservices. thinkjava.net" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
3.
<!--WSDL created by Apache Axis version: 1.4
4.
Built on Apr 22, 2006 (06:55:48 PDT)-->
5.
<wsdl:types>
6.
<schema elementFormDefault="qualified" targetNamespace="http://webservices. thinkjava.net" xmlns="http://www.w3.org/2001/XMLSchema">
7.
<element name="sayHelloWorld">
8.
<complexType>
9.
<sequence>
10.
<element name="name" type="xsd:string"/>
11.
</sequence>
12.
</complexType>
13.
</element>
14.
<element name="sayHelloWorldResponse">
15.
<complexType>
16.
<sequence>
17.
<element name="sayHelloWorldReturn" type="xsd:string"/>
18.
</sequence>
19.
</complexType>
20.
</element>
21.
</schema>
22.
</wsdl:types>
23.
<wsdl:message name="sayHelloWorldRequest">
24.
<wsdl:part element="impl:sayHelloWorld" name="parameters"/>
25.
</wsdl:message>
26.
<wsdl:message name="sayHelloWorldResponse">
27.
<wsdl:part element="impl:sayHelloWorldResponse" name="parameters"/>
28.
</wsdl:message>
29.
<wsdl:portType name="HelloWorld">
30.
<wsdl:operation name="sayHelloWorld">
31.
<wsdl:input message="impl:sayHelloWorldRequest" name="sayHelloWorldRequest"/>
32.
<wsdl:output message="impl:sayHelloWorldResponse" name="sayHelloWorldResponse"/>
33.
</wsdl:operation>
34.
</wsdl:portType>
35.
<wsdl:binding name="HelloWorldSoapBinding" type="impl:HelloWorld">
36.
<wsdlsoap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
37.
<wsdl:operation name="sayHelloWorld">
38.
<wsdlsoap:operation soapAction=""/>
39.
<wsdl:input name="sayHelloWorldRequest">
40.
<wsdlsoap:body use="literal"/>
41.
</wsdl:input>
42.
<wsdl:output name="sayHelloWorldResponse">
43.
<wsdlsoap:body use="literal"/>
44.
</wsdl:output>
45.
</wsdl:operation>
46.
</wsdl:binding>
47.
<wsdl:service name="HelloWorldService">
48.
<wsdl:port binding="impl:HelloWorldSoapBinding" name="HelloWorld">
49.
<wsdlsoap:address location="http://localhost:8080/SimpleSOAPExample/services/HelloWorld"/>
50.
</wsdl:port>
51.
</wsdl:service>
52.
</wsdl:definitions>
Universal Description, Discovery and
Integration(UDDI):
UDDI stands for Universal Description, Discovery and Integration.It is a directory service. Web services can register with a UDDI and make themselves available through it for discovery.
UDDI stands for Universal Description, Discovery and Integration.It is a directory service. Web services can register with a UDDI and make themselves available through it for discovery.
4. Web service design approaches:
Contract last or Bottom up approach:
When using contract last approach,you first write
your java code then you create web service contract(WSDL) .There are various
kinds of tools which can generate WSDL on the basis of java code.
Contract first or Top Down Approach :
It is reverse of contract first.Here you
first define web service contract.You define all the elements of WSDL first
then after that you create your java logic.
0 comments :
Post a Comment