WSDL - WSDL Namespaces

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?

  1. Avoid conflicts when combining multiple schemas.

  2. Organize elements (types, messages, bindings, etc.) into logical groups.

  3. Ensure interoperability by using standardized URIs.

  4. Allow reuse of common data types defined elsewhere (like XML Schema datatypes).


Commonly Used WSDL Namespaces

  1. WSDL Core Namespace

xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
  • Defines the WSDL elements (definitions, types, message, portType, binding, service).


  1. 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).


  1. 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.


  1. Target Namespace (tns)

xmlns:tns="http://example.com/weather"
  • A user-defined namespace for the current WSDL document.

  • Ensures the elements/messages defined here don’t conflict with others.


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).