Explain building blocks of web services in details.
In : BSc IT Subject : Web Application Development - ASP.NETWeb services are built using a set of standardized technologies and protocols that allow different applications to communicate over the internet. The main building blocks of web services include:
### 1. **XML (eXtensible Markup Language)**
- **Purpose**: Used to format and structure data for exchange between systems.
- **Role**: Acts as the foundation for data representation in web services.
- **Example**:
<Person>
<Name>John</Name>
<Age>30</Age>
</Person>
- Since XML is platform-independent, it allows diverse systems to understand shared data.
### 2. **SOAP (Simple Object Access Protocol)**
- **Purpose**: A protocol used to **send and receive messages** in a web service.
- **Features**:
- Uses XML for message formatting.
- Relies on HTTP or SMTP for transmission.
- Highly secure and supports ACID compliance (used in enterprise apps).
- **Structure of a SOAP Message**:
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope">
<soap:Header></soap:Header>
<soap:Body>
<GetUserResponse>
<User>John Doe</User>
</GetUserResponse>
</soap:Body>
<soap:Fault></soap:Fault>
</soap:Envelope>
- **Pros**: Secure, reliable, supports WS-Security, WS-ReliableMessaging.
- **Cons**: Heavyweight, slower due to large XML overhead.
### 3. **WSDL (Web Services Description Language)**
- **Purpose**: An XML-based file that **describes what a web service can do**, how to call it, and where it is located.
- **Contains**:
- **Service name**
- **Operations (methods)** available
- **Input/output parameters**
- **Communication protocol** (e.g., SOAP over HTTP)
- **Endpoint URL (address)**
- **Example**:
<definitions>
<message name="GetUserRequest">
<part name="userId" type="xs:int"/>
</message>
<portType name="UserServicePort">
<operation name="GetUser">
<input message="GetUserRequest"/>
<output message="GetUserResponse"/>
</operation>
</portType>
<binding type="UserServicePort" transport="HTTP">
<soap:binding style="rpc"/>
</binding>
<service name="UserService">
<port binding="UserServiceBinding">
<soap:address location="https://example.com/userservice.asmx"/>
</port>
</service>
</definitions>
- When you add a web service reference in Visual Studio, it reads the WSDL to generate client code.
### 4. **UDDI (Universal Description, Discovery, and Integration)**
- **Purpose**: A directory or registry where web services are **published and discovered**.
- **Function**:
- Businesses can **list their web services**.
- Clients can **search for services** they need (like a phone book).
- Example: A company publishes its payment processing web service in UDDI so others can find and use it.
- **Note**: UDDI is less commonly used today; modern APIs rely more on documentation (like Swagger) and API gateways.
### 5. **REST (Representational State Transfer) – Modern Alternative**
While not part of traditional SOAP-based web services, **REST has become a key building block** of modern web services.
- **Architecture style** (not a protocol).
- Uses standard **HTTP methods**: GET, POST, PUT, DELETE.
- Data formats: **JSON** (most common), XML.
- Lightweight and fast — ideal for mobile and web apps.
#### Example (REST API endpoint):
GET https://api.example.com/users/1
Response (JSON):
{
"id": 1,
"name": "John Doe"
}
- No need for WSDL or SOAP — uses simple URLs and returns easy-to-parse JSON.