Table of Contents
In this web service tutorial, we will see the introduction of webservices in java and some jargons of web services.
Webservices in java are used everywhere nowadays. When human interacts with any web page, it involves request and response via HTML. When you interact with the webpage, browser sends a request and then renders response and shows in form of HTML. Similarly, web services also involve request and response but in the form of XML or JSON or plain text. It generally used for other applications or programs to consume and make use of information.
For example:
You are creating a website which shows weather information of important cities in the world. You can actually consume already exposed web services and get the data for the cities. You will get the response in form of XML or JSON, you can parse it and show it on your website.
Let’s go to more formal definition now:
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(let’s say .Net developer) can access your function.
You can go through web services interview questions for interview questions on webservices in java.
Why you need to learn web services:
Reuse already developed(old) functionality into new software:
Let’s understand with the very simple example.Let’s 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 than developing new software for employee part, you can use old software and for other parts like infrastructure, you can develop your own functionalities.
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.
Interoperability :
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.
Ease of Integration:
Data is isolated between applications creating ’silos’. Web Services act as glue between these and enable easier communications within and across organizations.
Deployability :
Web Services are deployed over standard Internet technologies. This makes it possible to deploy Web Services even over the firewall 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.
Some jargons used in Webservices in java:
Simple Object Access Protocol(SOAP):
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 namespace 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.The 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:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
<?xml version="1.0" encoding="UTF-8"?> <wsdl:definitions targetNamespace="http://webservices.javapostsforlearning.arpit.org" xmlns:apachesoap="http://xml.apache.org/xml-soap" xmlns:impl="http://webservices.javapostsforlearning.arpit.org" xmlns:intf="http://webservices.javapostsforlearning.arpit.org" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <!--WSDL created by Apache Axis version: 1.4 Built on Apr 22, 2006 (06:55:48 PDT)--> <wsdl:types> <schema elementFormDefault="qualified" targetNamespace="http://webservices.javapostsforlearning.arpit.org" xmlns="http://www.w3.org/2001/XMLSchema"> <element name="sayHelloWorld"> <complexType> <sequence> <element name="name" type="xsd:string"/> </sequence> </complexType> </element> <element name="sayHelloWorldResponse"> <complexType> <sequence> <element name="sayHelloWorldReturn" type="xsd:string"/> </sequence> </complexType> </element> </schema> </wsdl:types> <wsdl:message name="sayHelloWorldRequest"> <wsdl:part element="impl:sayHelloWorld" name="parameters"/> </wsdl:message> <wsdl:message name="sayHelloWorldResponse"> <wsdl:part element="impl:sayHelloWorldResponse" name="parameters"/> </wsdl:message> <wsdl:portType name="HelloWorld"> <wsdl:operation name="sayHelloWorld"> <wsdl:input message="impl:sayHelloWorldRequest" name="sayHelloWorldRequest"/> <wsdl:output message="impl:sayHelloWorldResponse" name="sayHelloWorldResponse"/> </wsdl:operation> </wsdl:portType> <wsdl:binding name="HelloWorldSoapBinding" type="impl:HelloWorld"> <wsdlsoap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/> <wsdl:operation name="sayHelloWorld"> <wsdlsoap:operation soapAction=""/> <wsdl:input name="sayHelloWorldRequest"> <wsdlsoap:body use="literal"/> </wsdl:input> <wsdl:output name="sayHelloWorldResponse"> <wsdlsoap:body use="literal"/> </wsdl:output> </wsdl:operation> </wsdl:binding> <wsdl:service name="HelloWorldService"> <wsdl:port binding="impl:HelloWorldSoapBinding" name="HelloWorld"> <wsdlsoap:address location="http://localhost:8080/SimpleSOAPExample/services/HelloWorld"/> </wsdl:port> </wsdl:service> </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
Web service design approaches:
Types of webservices in java:
You can read about differences and usage of REST and SOAP web services.
That’s all about the webservices in java.
Great BLOG .. !!!!
Wonderful job guy ,carry on ….
Nice, Thank you very much.
Very nice analysis on the WSDL, helps in taking things forward to learn webservice
plz visit my blog for core java conceptsjava by vikas
thank you…..
very helpful..thanks
willplzz provide link for core java concepts
Hi Sreenivas,
Please find link for core java concepts.
https://www.java2blog.com/2017/05/core-java-tutorial-for-beginners-experienced.html
great thanks
thanks
Finally a good tutorial about web service! THANKS!
but java does not have RIA controls like .net silverlight…
hiiiiiiiiiiiiii
What's the main difference between Java and python? which one is more easy to learn? i am interested to use it for web service development.
really nice…
very good work and easily understandable
Thank you so much for providinig such a nice tutorial
thanks mr. devloper , beautiful start in webservice
Thank you. I am glad you liked it. 🙂
I love ur simple codes.. I refer to ur website wen i hav to begin wid a particular technology.. bt the bookish definitions dont suit ur simple website.. u cud actually explain all the definitions in a layman terms so tat its easy fr freshers lik me to learn theory as well frm ur site.. Awsome site!!! thanks!!!
That’s a good compliment for me. I would really try to make the definition as simple as possible.
Thank you. I am glad that you liked my blog 🙂
That was nice tutorial.
Nice tutorial
nice tutorials.
Thanxxxx nice tutorial
Thanks a lot
Wonderful job guy ,carry on .
Web Development Islamabad
It's very nice tutorials. keep posting…
Thank you Arpit
Asewome tutorial for beginners….Clear and easy understandable
too good
Nice one!
Very Clean and Easy to understand.
great
a very good blog thanks I was looking for exactly definition of this , thanks a lot 🙂
Thanks for sharing__
Well , blog is nice.
But i always confised about webservice.. What to write, when to write, where to write ?
i like so much, i love this blog
Thank you. I am glad you liked it. 🙂
very nice examples…very much helpful to learn web services. Expecting more examples on Web Services 🙂
Thank you. I am glad you liked it 🙂
Thanks its really working
This really good blog.
But I thing root element of wsdl is “Definition”.
how to create a web services to print hello world using java
great blog
Thank you. I am glad you liked it.
Good technology, very nice description. Thanks for sharing…
great
Thank you very much! It is really very helpful 🙂
Thank you. I am glad you liked it 🙂
Your tutorial is very good. Unlike other beginners tutorials which simply show us the annotations to be used for web services, your tutorial actually gives proper explanation on each annotation. I found it very useful and easy to understand. Thanks much for posting this.
Thank you. I am glad you liked it.
Useful Information, tnx.
Thanks 🙂
Hi<
u did u great work
please update with different tutorials(In spring )
Hi Sreenivas,
Thank you.
I had already written tutorials on Spring, Spring MVC and Spring Boot.
If you are looking for more concepts, just let me know.
https://www.java2blog.com/2012/08/introduction-to-spring-framework.html
https://www.java2blog.com/2015/09/spring-mvc-hello-world-example.html
https://www.java2blog.com/2017/07/spring-boot-tutorial.html
Very Simple, informative, easy to understand, in detailed… Superb Man. Its really helpful.