Saturday, February 20, 2010

WSDL sucks - anatomy of a WSDL, WSDL for dummies

A very good presentation on the differences between WSDL 1.1 and 2.0 is here

This is a sample WSDL 2.0 file:

service has binding, binding has interface, interface has operations, operation has input and output (and fault)

<?xml  version="1.0" encoding="UTF-8"?>
<wsdl:description targetNamespace="http://new.webservice.namespace" xmlns:wsdl="" xmlns:wsoap="" xmlns:whttp="" xmlns:xs="" xmlns:tns="http://new.webservice.namespace">
        <xs:schema targetNamespace="http://new.webservice.namespace" elementFormDefault="qualified">
            <xs:element name="NewMessageRequest" type="xs:string"/>
            <xs:element name="NewMessageResponse" type="xs:string"/>
    <wsdl:interface name="NewInterface">
        <wsdl:operation name="NewOperation" pattern="">
            <wsdl:input messageLabel="In" element="tns:NewMessageRequest"/>
            <wsdl:output messageLabel="Out" element="tns:NewMessageResponse"/>
    <wsdl:binding name="NewBinding" interface="tns:NewInterface" type="" wsoap:protocol="">
        <wsdl:operation ref="tns:NewOperation" wsoap:mep=""/>
    <wsdl:service name="NewService" interface="tns:NewInterface">
        <wsdl:endpoint name="NewEndpoint" binding="tns:NewBinding"/>

This is the same service in WSDL 1.1 - notice the verbosity compared to 2.0:

service has binding, binding has porttype, porttype has operations, operation has message... what a mess!

<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions xmlns:wsdl="" xmlns:soap="" xmlns:http="" xmlns:xs="" xmlns:soapenc="" xmlns:mime="" xmlns:xsi="" xmlns:tns="http://new.webservice.namespace" targetNamespace="http://new.webservice.namespace">
        <xs:schema targetNamespace="http://new.webservice.namespace" elementFormDefault="qualified"/>
    <wsdl:message name="NewMessageRequest">
        <wsdl:part name="parameter" type="xs:string"/>
    <wsdl:message name="NewMessageResponse">
        <wsdl:part name="parameter" type="xs:string"/>
    <wsdl:portType name="NewPortType">
        <wsdl:operation name="NewOperation">
            <wsdl:input message="tns:NewMessageRequest"/>
            <wsdl:output message="tns:NewMessageResponse"/>
    <wsdl:binding name="NewBinding" type="tns:NewPortType">
        <soap:binding style="document" transport=""/>
        <wsdl:operation name="NewOperation">
            <soap:operation soapAction="urn:#NewOperation"/>
                <soap:body use="literal"/>
                <soap:body use="literal"/>
    <wsdl:service name="NewService">
        <wsdl:port name="NewPort" binding="tns:NewBinding">
            <soap:address location="No Target Adress"/>

I hate WSDL, and the whole XML paraphernalia created to implement distributed computing around the XML paradigm.
I am trying to understand why I hate this entire technology.
Being a Java developer, I like the extreme coherence of Data and Interfaces definitions implemented in Java:
if you break something, you will immediately notice at design time.
With XML and WSDL, you always have the impression of handling a wobbly jellyfish, overly complex and redundant, leaving open holes for ambiguity and crappy implementations.
In fact, in my own experience AXIS2, SOAPUI and Clientgen operate differently, a WSDL which works with the first 2 doesn't work in Clientgen.... CRAP!

In a WSDL you have DEFINITIONS of public services.

NAMESPACES are used to make names less ambiguous, and should regarded as packages. Their syntax in reality is obscure and ambiguous.

SERVICES are exposed in the service URL; http://host:port/WEB_CONTEXT_ROOT/service

A SERVICE is associated to a BINDING, which defines the protocol (SOAP) and the way to pass arguments (DOCUMENT).

in the BINDING you MAY redefine OPERATIONS, but they are already defined in the PORT TYPE.
OPERATIONS are associated at times with SOAP ACTION.

A PORT TYPE is a misnomer, in WSDL 2.0 it is called INTERFACE, which is what it actually is. It defines OPERATIONS (=method) and their MESSAGES (=parameters).

In TYPES there is the type definition of method parameters.

So all in all you have a very complex and articulated document to do very simple stuff:
Why all this could not be done in a simpler way....finally leaving the developer to rely on automated tools.... EJB 2.0 reloaded.... we already know that it will all end up in a EJB 3.0 where AT LAST the good stuff is done.... so why not do it since the beginning...

Let's look in Wikipedia the changes made in WSDL 2.0:

- Removal of message constructs
EXACTLY! There should be only OPERATIONS. MESSAGES are useless indirection.

- PortTypes renamed to interfaces
PortTypes are simply a list of Operations... so... call it Interface, no?

- Ports renamed to endpoints.
In fact it simply defines a URL for the Service

Furthermore, some definitions - like endpoint - have been inlined in WSDL 2.0, making the document more compact and readable.

WSDL 2.0 is barely tolerable, WDSL 1.0 is simply outrageous, my grand mother could have done a better job.

UNFORTUNATELY OSB 3.0 doesn't seem to recognize this WSDL 2.0 format, when I try to import the WSLD it complains about:

An error occurred creating the resource:
org.apache.xmlbeans.XmlException: error: The document is not a definitions@ document element mismatch got description@

1 comment:

Pascal Grange said...

Explicit promotion ;)

For desperate Java developpers that have to request SOAP web-services, there is a new API available in a early version :

It fits in one jar.

It does not require to generate a bunch of Java code before requesting the web-service.

Until SOAP is definitely deprecated, this may be helpfull.