Join Patrick Royal for an in-depth discussion in this video What are web services?, part of Building Web Services with Java EE.
What is a web service? The obvious answer to that question is that it is the service provided over a network. But that can seem somewhat vague and generic. Virtually everything on the internet from smart phone apps to databases can be thought of as a service provided via the Internet. However, there is an important difference between a web service and a website. A website can be thought of as a communication between two humans, where the content is arranged in such a way that each human can read and understand it.
A web service, on the other hand, is the communication between two computers. Instead of text and graphics, it transmits code requests that interact directly with another computer, often without any human intervention. Computers can use web services to communicate directly with one another at a low level. Sending and receiving requests for raw data or sharing functions and methods. In this sense, a web service is the back end part of the world wide web.
For example, imagine that you want to be able to access stock price data. It is stored on an external server in raw form, so there might be a simple algorithm on that server that downloads the data, convert it to something useful and then sends it to you. If the algorithm is public and can be run by external computers, then it's a web service. You might wonder why web services are necessary. Couldn't you just download a function for stock data conversion from the site once and then never have to access them again? Well, there are a number of disadvantages with this strategy.
If the functions are ever updated, then you'll have to download them again to update your local copy. If the database you are accessing changes, you have to make a note of that change and rewrite your code to interface with the new database. A web service allows us to leave key functions on the source server instead of pulling them down to the local browsers. This makes it much easier to update and modify them from a centralized location. This process is not quite as simple as copying and pasting a function to another computer, though. Within a single program, communication between functions is simple and straightforward.
The Java program supports certain data types universally. So any Java method can communicate with any other Java method by passing in data structures like ints and arrays. Similarly, any method written in C, Python, or any other programming language can communicate with other methods in its language through common data structures. However, the Internet consists of billions of different computers interacting with each other through a variety of different protocols and functions. And there's no guarantee that any two programs that need to interact are written in the same language.
Web services bridge this gap by providing compatibility across multiple languages and operating systems. Rather than requiring the user to know the details and precise code structure of every program they access, a web service provides a set of standard information in universally readable format. Programmers often call this the black box method of programming. For maximum compatibility and flexibility, users should be able to effectively interact with the program with as little information as possible.
The ultimate universal language for modern computers is something called XML, or extensible mark-up language. This format is essentially nothing more than plain text with a series of very simple tags creating a hierarchy. Every computer can interpret text. So, XML is universally compatible while still being flexible enough to support complex transmissions of information. Web services communicate through the web services description language or WSDL which is based in the XML format.
Using this format it's easy to transmit all the information required to use a program in a format understandable by any computer.
- What are Java EE web services?
- Creating a simple service
- Building, packaging, and deploying your service
- Understanding the basic syntax
- Working with WSDL (Web Service Definition Language)
- Exploring SOAP (Simple Object Access Protocol)
- Exploring the syntax and design of REST (Representation State Transfer)
- Programming a web service in Java EE
- Debugging and optimizing your code