Search code examples
xmlxsdwsdl

WSDL for overloaded elements in legacy service


I am trying to write a WSDL 1.1 definition for a legacy service whose documentation specifies XML schema that overload root (and other) elements with different definitions for different messages.

A trivial example involves the following schema for one message:

<schema xmlns="http://www.w3.org/2001/XMLSchema"
  targetNamespace="urn:example:namespace">
    <element name="message" type="boolean"/>
</schema>

and the following for another:

<schema xmlns="http://www.w3.org/2001/XMLSchema"
  targetNamespace="urn:example:namespace">
    <element name="message" type="date"/>
</schema>

One cannot therefore directly import each message's schema as given into the WSDL, as it introduces ambiguity over the definition of {urn:example:namespace}message.

Nor can one rewrite the schema so that such overloaded elements validate both message types, as this would wrongly imply that either type is valid for either message:

<schema xmlns="http://www.w3.org/2001/XMLSchema"
  targetNamespace="urn:example:namespace">
    <element name="message">
        <simpleType>
            <union memberTypes="boolean date"/>
        </simpleType>
    </element>
</schema>

It strikes me that each message should be defined within its own namespace, or else use unambiguous element names within the same namespace. However, such changes would break the legacy service contract and are therefore sadly not an option.

Grateful for your thoughts and suggestions on how, if at all, one can resolve this dilemma!


Solution

  • Richard Schneider's answer prompted me to realise that I can overcome the original question in the following way:

    <schema xmlns="http://www.w3.org/2001/XMLSchema"
      targetNamespace="urn:example:namespace">
        <complexType name="booleanMessageType">
            <xs:sequence>
                <element name="message" type="boolean"/>
            </xs:sequence>
        </complexType>
        <complexType name="dateMessageType">
            <xs:sequence>
                <element name="message" type="date"/>
            </xs:sequence>
        </complexType>
    </schema>
    

    and then the WSDL:

    <definitions xmlns="http://schemas.xmlsoap.org/wsdl/"
      xmlns:ns="urn:example:namespace"
      targetNamespace="urn:example:wsdl">
        <import namespace="urn:example:namespace" location="schema.xsd"/>
        <message name="BooleanMessage">
            <part name="body" type="ns:booleanMessageType"/>
        </message>
        <message name="DateMessage">
            <part name="body" type="ns:dateMessageType"/>
        </message>
        <!-- remainder of WSDL omitted for brevity -->
    </definitions>
    

    This gave rise to a secondary question, which I will link as a comment to this answer once posted.