Skip to content
Tutorials Center
My learning

Topics

Lesson 1 of 36 ยท Getting Started

What Are Web Services?

Learn what a web service is, why programs talk to each other over a network, and how contracts, messages and transports fit together, with a runnable service on loopback.

A web service is a program that offers a function to other programs over a network. A person uses a browser to read a page; a program uses a web service to ask another program for data or to ask it to do something. A shop asks a payment service to charge a card. A travel site asks twenty airline services for prices. A weather app asks a forecast service for tomorrow's temperature.

This track is about the family of web services built around SOAP, XML and WSDL, and how they compare with the newer REST and JSON style. Before the details, you need the big picture: what a web service is made of, who plays which role, and why companies still run thousands of SOAP services today.

The three ingredients

Every web service, SOAP or not, has the same three ingredients:

  1. A contract. A description of what you may ask for: the operations, the inputs, the outputs, and the errors. Without a contract, a client has to guess.
  2. A message format. The bytes that travel: XML, JSON, or something else. Both sides must agree on the shape.
  3. A transport. The pipe the message travels through. For web services this is usually HTTP, but SOAP can also ride on SMTP (email), JMS queues or plain TCP.

A web service has three parts

Contract What can I ask?
Message How is it written?
Transport How does it travel?

SOAP fixes all three in a standard.

1 / 3

Client and service

The program that asks is the client (also called the consumer or requester). The program that answers is the service (also called the provider). The pair exchange a request and a response. Nothing about this is specific to the web: a function call has a caller and a callee. A web service is a function call that crosses a network boundary, which brings three new problems:

  • The two programs may be written in different languages, so they cannot share objects or memory. Everything must be turned into text or bytes (this is called serialization).
  • The network can be slow, can drop messages and can be attacked, so errors and security matter far more than in a local call.
  • The two sides are developed by different teams, often in different companies, so the contract must stay stable.

A first service you can run

Our editor cannot reach the internet, but it can start a server on the loopback address and call it, which is all we need to see the idea. The program below starts a tiny service with one operation, GET /temperature?city=..., and a client that calls it.

Node.js A tiny service and its client

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with node:readline or process.stdin), it gets the next line from this box.

The client sees only three things: the URL, the request it sends and the response it gets back. It does not know that the service stores the temperatures in a plain object. That hiding of the inside is the main reason web services exist: the provider can replace the object with a database tomorrow and no client breaks, as long as the contract is kept.

Contracts make strangers cooperate

In the example the "contract" is only in your head: you know the URL and the field names. For two companies that is not enough. SOAP services publish a machine-readable contract called WSDL (Web Services Description Language), which lists every operation and the exact shape of every message. Tools read the WSDL and generate client code, so a Java service can be called from C# with no manual work. You will meet WSDL in WSDL structure.

The next program shows the idea in miniature: a contract as plain data, and a function that checks a message against it before the service runs.

Node.js A contract checked before the call

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with node:readline or process.stdin), it gets the next line from this box.

A real WSDL does the same job, but in XML, and with richer types.

A short map of the web-service world

Over the years several styles of web service appeared:

Style Message format Contract Typical use
SOAP XML envelope WSDL + XSD Enterprise, banking, government
REST JSON (or XML, HTML) OpenAPI (optional) Public web APIs, mobile apps
XML-RPC XML none Older, simple remote calls
gRPC Protocol Buffers .proto file Fast service-to-service calls
GraphQL JSON schema Flexible client queries

SOAP is the oldest of the serious, standardized styles. It is verbose, but it comes with a full toolbox for security, transactions and reliability, and that is why banks, insurers, airlines and governments still run it. A later chapter of this track compares REST and SOAP honestly.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What is the main job of the contract of a web service?

    A contract (for SOAP, a WSDL) says what operations exist and what their inputs and outputs look like, so clients and providers can work independently.
  2. 2. Which of these is NOT one of the three ingredients named in this lesson?

    The three ingredients are contract, message format and transport. What the service uses internally, such as a database, is hidden from clients.
  3. 3. Why must data be serialized before it crosses the network?

    Different languages and machines cannot share objects, so values are turned into text or bytes that both sides can read.
  4. 4. Which transport can SOAP use besides HTTP?

    SOAP is transport-neutral. HTTP is the common choice, but bindings for SMTP, JMS and TCP exist.

Summary

  • A web service exposes a function to other programs over a network.
  • Every service has a contract, a message format and a transport.
  • Clients depend only on the contract, so the provider may change its inside freely.
  • SOAP, REST, gRPC and others are different styles of web service.
  • SOAP is standardized, XML based and common in enterprise and government systems.

Next: A Short History of SOAP