SOAP - Namespace in SOAP
What is a Namespace in SOAP?
-
In XML, a namespace is a way to uniquely identify elements and attributes so there are no naming conflicts.
-
In SOAP, namespaces are used to distinguish SOAP framework tags from your service-specific tags.
-
They’re declared using
xmlns
attributes.
Why Namespaces are Needed in SOAP
-
Avoids Naming Conflicts
-
Example: Your service might have an element called
<Header>
, but SOAP itself already has a<Header>
. Namespaces keep them separate.
-
-
Clarity & Consistency
-
The client knows which XML elements belong to SOAP itself and which belong to your business logic.
-
-
Interoperability
-
Different services can safely exchange data without accidentally mixing up tags.
-
SOAP Namespaces You’ll Commonly See
-
SOAP Envelope Namespace
-
SOAP 1.1:
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
-
SOAP 1.2:
xmlns:soap12="http://www.w3.org/2003/05/soap-envelope"
-
Defines core SOAP elements like
<soap:Envelope>
,<soap:Header>
,<soap:Body>
.
-
-
XML Schema Namespace
-
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
-
Defines data types (string, int, date, etc.).
-
-
WSDL Namespace
-
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
-
Used in WSDL files to describe services.
-
-
Service-Specific Namespace
-
Example:
xmlns:tns="http://example.com/hello"
-
This is where your custom operations and data types live.
-
SOAP Message Example with Namespaces
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:tns="http://example.com/hello">
<soap:Header>
<tns:AuthHeader>
<tns:Username>admin</tns:Username>
<tns:Password>12345</tns:Password>
</tns:AuthHeader>
</soap:Header>
<soap:Body>
<tns:SayHello>
<tns:name>John</tns:name>
</tns:SayHello>
</soap:Body>
</soap:Envelope>
Breakdown:
-
soap:
→ Standard SOAP elements (Envelope, Header, Body). -
xsd:
→ Standard XML data types (not used in this snippet, but available). -
tns:
→ Your service’s custom operations (SayHello, AuthHeader, etc.).
In short:
Namespaces in SOAP separate “standard” SOAP parts from your application’s data, preventing conflicts and ensuring smooth interoperability across platforms.