Il Web Services Description Language (WSDL) è un linguaggio formale in formato XML utilizzato per la creazione di "documenti" per la descrizione di Web service.

Descrizione

Mediante WSDL può essere infatti descritta l'interfaccia pubblica di un Web service (ovvero una descrizione basata su XML) che indica come interagire con un determinato servizio.

Un "documento" WSDL contiene infatti, relativamente al Web service descritto, informazioni su:

Le operazioni supportate dal Web service ed i messaggi che è possibile scambiare con lo stesso sono descritti in maniera astratta e quindi non collegati ad uno specifico protocollo di rete e ad uno specifico formato.

Il WSDL è solitamente utilizzato in combinazione con SOAP e XML Schema per rendere disponibili Web service su reti aziendali o su internet: un programma client può, infatti, "leggere" il documento WSDL relativo ad un Web service per determinare quali siano le funzioni messe a disposizione sul server e attraverso il protocollo SOAP utilizzare una o più delle funzioni elencate dal WSDL.

La versione 1.1 di WSDL non è stata adottata come standard dal World Wide Web Consortium (W3C).

Il 26 giugno 2007 la versione 2.0 è stata promossa a standard ufficiale (in forma di "raccomandazione") dal W3C.

Stili e codifiche

Un documento WSDL può essere caratterizzato da quattro distinte combinazioni di stili e codifiche:[1][2]

Esempio di documento WSDL 2.0

<?xml version="1.0" encoding="UTF-8"?>
<description xmlns="http://www.w3.org/ns/wsdl" 
             xmlns:tns="http://www.example.com/wsdl20sample" 
             xmlns:whttp="http://www.w3.org/ns/wsdl/http"
             xmlns:wsoap="http://www.w3.org/ns/wsdl/soap"
             targetNamespace="http://www.example.com/wsdl20sample">

<!-- Abstract types -->
   <types>
      <xs:schema xmlns="http://www.example.com/wsdl20sample"
                 xmlns:xs="http://www.w3.org/2001/XMLSchema" 
                 targetNamespace="http://www.example.com/wsdl20sample">
                 
         <xs:element name="request">
            <xs:complexType>
               <xs:sequence>
                  <xs:element name="header" maxOccurs="unbounded">
                     <xs:complexType>
                        <xs:simpleContent>
                           <xs:extension base="xs:string">
                              <xs:attribute name="name" type="xs:string" use="required"/>
                           </xs:extension>
                        </xs:simpleContent>
                     </xs:complexType>
                  </xs:element>
                  <xs:element name="body" type="xs:anyType" minOccurs="0"/>
               </xs:sequence>
               <xs:attribute name="method" type="xs:string" use="required"/>
               <xs:attribute name="uri" type="xs:anyURI" use="required"/>
            </xs:complexType>
         </xs:element>
         
         <xs:element name="response">
            <xs:complexType>
               <xs:sequence>
                  <xs:element name="header" maxOccurs="unbounded">
                     <xs:complexType>
                        <xs:simpleContent>
                           <xs:extension base="xs:string">
                              <xs:attribute name="name" type="xs:string" use="required"/>
                           </xs:extension>
                        </xs:simpleContent>
                     </xs:complexType>
                  </xs:element>
                  <xs:element name="body" type="xs:anyType" minOccurs="0"/>
               </xs:sequence>
               <xs:attribute name="status-code" type="xs:anySimpleType" use="required"/>
               <xs:attribute name="response-phrase" use="required"/>
            </xs:complexType>
         </xs:element>
      </xs:schema>
   </types>

<!-- Abstract interfaces -->
   <interface name="RESTfulInterface">
      <fault name="ClientError" element="tns:response"/>
      <fault name="ServerError" element="tns:response"/>
      <fault name="Redirection" element="tns:response"/>
      <operation name="Get" pattern="http://www.w3.org/ns/wsdl/in-out">
         <input messageLabel="GetMsg" element="tns:request"/>
         <output messageLabel="SuccessfulMsg" element="tns:response"/>
      </operation>
      <operation name="Post" pattern="http://www.w3.org/ns/wsdl/in-out">
         <input messageLabel="PostMsg" element="tns:request"/>
         <output messageLabel="SuccessfulMsg" element="tns:response"/>
      </operation>
      <operation name="Put" pattern="http://www.w3.org/ns/wsdl/in-out">
         <input messageLabel="PutMsg" element="tns:request"/>
         <output messageLabel="SuccessfulMsg" element="tns:response"/>
      </operation>
      <operation name="Delete" pattern="http://www.w3.org/ns/wsdl/in-out">
         <input messageLabel="DeleteMsg" element="tns:request"/>
         <output messageLabel="SuccessfulMsg" element="tns:response"/>
      </operation>
   </interface>

<!-- Concrete Binding Over HTTP -->
   <binding name="RESTfulInterfaceHttpBinding" interface="tns:RESTfulInterface" 
            type="http://www.w3.org/ns/wsdl/http">
      <operation ref="tns:Get" whttp:method="GET"/>
      <operation ref="tns:Post" whttp:method="POST" 
                 whttp:inputSerialization="application/x-www-form-urlencoded"/>
      <operation ref="tns:Put" whttp:method="PUT" 
                 whttp:inputSerialization="application/x-www-form-urlencoded"/>
      <operation ref="tns:Delete" whttp:method="DELETE"/>
   </binding>
   
<!-- Concrete Binding with SOAP-->
   <binding name="RESTfulInterfaceSoapBinding" interface="tns:RESTfulInterface" 
            type="http://www.w3.org/ns/wsdl/soap" 
            wsoap:protocol="http://www.w3.org/2003/05/soap/bindings/HTTP/"
            wsoap:mepDefault="http://www.w3.org/2003/05/soap/mep/request-response">
      <operation ref="tns:Get" />
      <operation ref="tns:Post" />
      <operation ref="tns:Put" />
      <operation ref="tns:Delete" />
   </binding>
   
<!-- Web Service offering endpoints for both the bindings-->
   <service name="RESTfulService" interface="tns:RESTfulInterface">
      <endpoint name="RESTfulServiceRestEndpoint" 
                binding="tns:RESTfulInterfaceHttpBinding" 
                address="http://www.example.com/rest/"/>
      <endpoint name="RESTfulServiceSoapEndpoint" 
                binding="tns:RESTfulInterfaceSoapBinding" 
                address="http://www.example.com/soap/"/>
   </service>
</description>

Note

  1. ^ (EN) Russel Butek, Which style of WSDL should I use?, su ibm.com, IBM, 31 ottobre 2003. URL consultato il 10 settembre 2018 (archiviato il 23 agosto 2018).
  2. ^ Marco Parente, WSDL: stili e codifiche, su HTML.it (archiviato il 22 gennaio 2014).

Voci correlate

  Portale Internet: accedi alle voci di Wikipedia che trattano di internet