What are Namespaces in WSDL?
Namespaces in WSDL are unique identifiers (URIs) that distinguish elements and types defined in one XML document from those in another.
Since WSDL is XML-based and often imports external schemas, namespaces are essential to avoid naming conflicts and ensure that each element is uniquely identified.
Example: Two different services might both define an element called <Result>. With namespaces, they can be differentiated as serviceA:Result vs. serviceB:Result.
Why Are Namespaces Important in WSDL?
-
Avoid conflicts when combining multiple schemas.
-
Organize elements (types, messages, bindings, etc.) into logical groups.
-
Ensure interoperability by using standardized URIs.
-
Allow reuse of common data types defined elsewhere (like XML Schema datatypes).
Commonly Used WSDL Namespaces
-
WSDL Core Namespace
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
-
Defines the WSDL elements (definitions, types, message, portType, binding, service).
-
SOAP Binding Namespace
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
-
Used for SOAP-specific extensibility elements (soap:binding, soap:operation, soap:body, soap:address).
-
XML Schema Namespace
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
-
Provides data types (xsd:string, xsd:int, etc.).
-
Used in <types> section for defining complex and simple data structures.
-
Target Namespace (tns)
xmlns:tns="http://example.com/weather"
Example with Namespaces
<definitions name="WeatherService"
targetNamespace="http://example.com/weather"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:tns="http://example.com/weather">
<wsdl:message name="GetWeatherRequest">
<wsdl:part name="city" type="xsd:string"/>
</wsdl:message>
<wsdl:message name="GetWeatherResponse">
<wsdl:part name="forecast" type="xsd:string"/>
</wsdl:message>
</definitions>
Here:
-
wsdl: prefixes WSDL core elements.
-
soap: is used for SOAP binding details.
-
xsd: refers to schema-defined datatypes.
-
tns: identifies elements defined in this WSDL itself.
Summary
-
WSDL namespaces = labels to distinguish XML elements.
-
They prevent conflicts, support modularity, and enable interoperability.
-
Common namespaces include WSDL, SOAP, XSD, and tns (target namespace).