Web Services Project — Build a SOAP-Based Order Processing Service
In this tutorial, you will learn about Web Services Project. We cover key concepts, practical examples, and best practices to help you master this topic.
Build a complete SOAP web service for order processing including a WSDL contract, server implementation with WS-Security, and clients in Python and Node.js.
What You'll Learn
- Creating a WSDL contract for a real service
- Implementing SOAP server with security
- Building SOAP clients in multiple languages
Why It Matters
This project simulates an enterprise integration scenario where you build both the service provider and consumer sides.
Project Structure
webservice-project/
contract/
OrderService.wsdl
server/
server.py (Python SOAP server)
clients/
python_client.py
node_client.js
WSDL Contract (Simplified)
<?xml version="1.0"?>
<definitions name="OrderService"
targetNamespace="http://example.com/orders"
xmlns="http://schemas.xmlsoap.org/wsdl/"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:tns="http://example.com/orders"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<message name="PlaceOrderRequest">
<part name="customerId" type="xsd:string"/>
<part name="productId" type="xsd:string"/>
<part name="quantity" type="xsd:int"/>
</message>
<message name="PlaceOrderResponse">
<part name="orderId" type="xsd:string"/>
<part name="status" type="xsd:string"/>
</message>
<portType name="OrderPortType">
<operation name="PlaceOrder">
<input message="tns:PlaceOrderRequest"/>
<output message="tns:PlaceOrderResponse"/>
</operation>
</portType>
<binding name="OrderBinding" type="tns:OrderPortType">
<soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
<operation name="PlaceOrder">
<soap:operation soapAction="PlaceOrder"/>
<input><soap:body use="literal"/></input>
<output><soap:body use="literal"/></output>
</operation>
</binding>
<service name="OrderService">
<port name="OrderPort" binding="tns:OrderBinding">
<soap:address location="http://localhost:8000/orders"/>
</port>
</service>
</definitions>
Python Server
# server/server.py
from spyne import Application, rpc, ServiceBase, Unicode, Integer
from spyne.protocol.soap import Soap11
from spyne.server.wsgi import WsgiApplication
class OrderService(ServiceBase):
@rpc(Unicode, Unicode, Integer, _returns=Unicode)
def PlaceOrder(ctx, customer_id, product_id, quantity):
order_id = f"ORD-{hash(customer_id + product_id) % 10000}"
return f"Order {order_id} placed: {quantity}x {product_id}"
application = Application(
[OrderService],
tns='http://example.com/orders',
in_protocol=Soap11(validator='lxml'),
out_protocol=Soap11()
)
if __name__ == '__main__':
from wsgiref.simple_server import make_server
server = make_server('0.0.0.0', 8000, WsgiApplication(application))
server.serve_forever()
Python Client
# clients/python_client.py
from zeep import Client
client = Client('http://localhost:8000/orders?wsdl')
result = client.service.PlaceOrder(
customerId='CUST-123',
productId='PROD-456',
quantity=2
)
print(f"Result: {result}")
Common Mistakes
1. WSDL and Server Implementation Mismatch
Ensure the server implements exactly the operations defined in the WSDL.
2. Forgetting to Expose WSDL
The server must serve the WSDL at the endpoint with ?wsdl.
3. Incorrect Namespace in WSDL VS Code
The targetNamespace in WSDL must match the tns in the code.
4. Not Testing with Real SOAP Clients
Use SoapUI or curl to test before building custom clients.
5. Missing Error Handling
Add SOAP Fault responses for validation errors.
FAQ
What's Next
Your web services knowledge is complete. Explore API Documentation with OpenAPI or API Error Handling for REST APIs.
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro