Comprensione di base della struttura WSDL – Spiegazione (linguaggio di descrizione del servizio Web).
Pubblicato: 2020-08-24Potresti aver visto il mio post precedente su SOAP vs. REST call. Oggigiorno le aziende stanno passando alle chiamate di servizio REST, ma la maggior parte delle aziende utilizza ancora SOAP su REST. Questo tutorial spiega le basi di WSDL (Web Service Description Language).
Se hai una delle seguenti domande, sei nel posto giusto:
- Che cos'è il WSDL (Web Services Description Language)?
- Esercitazione WSDL
- Spiegazione del WSDL (Web Services Description Language).
- Esempi di WSDL – Linguaggio di descrizione del servizio Web
Linguaggio di descrizione dei servizi Web (WSDL)
In Java Web Development World, WSDL è un formato XML per descrivere i servizi di rete come un insieme di endpoint che operano su messaggi contenenti informazioni orientate ai documenti o alle procedure.
Le operazioni e i messaggi vengono descritti in modo astratto e quindi associati a un protocollo di rete e un formato di messaggio concreti per definire un endpoint. Gli endpoint concreti correlati vengono combinati in endpoint astratti (servizi).
WSDL è estensibile per consentire la descrizione degli endpoint e dei relativi messaggi indipendentemente dai formati dei messaggi o dai protocolli di rete utilizzati per comunicare, tuttavia, gli unici binding descritti in questo documento descrivono come utilizzare WSDL
insieme a SOAP 1.1, HTTP GET/POST e MIMO.

Un altro deve leggere:
- Crea WSDL di esempio in Eclipse e genera client
- Come creare un servizio RESTful con Java utilizzando JAX-RS e Jersey (esempio)
In altre parole: un documento WSDL definisce i servizi come raccolte di endpoint di rete, o ports
. In WSDL, la definizione astratta di endpoint e messaggi è separata dalla loro distribuzione di rete concreta o dalle associazioni del formato dei dati. Ciò consente il riutilizzo di definizioni astratte: messages
, che sono descrizioni astratte dei dati scambiati, e tipi di porta che sono raccolte astratte di operazioni.
Le specifiche concrete del protocollo e del formato dei dati per un particolare tipo di porta costituiscono un binding
riutilizzabile. Una porta viene definita associando un indirizzo di rete a un'associazione riutilizzabile e una raccolta di porte definisce un servizio.
Quindi, un documento WSDL utilizza i seguenti elementi nella definizione dei servizi di rete:
-
Types
: un contenitore per le definizioni dei tipi di dati che utilizzano un sistema di tipi (comeXSD
). -
Message
: una definizione astratta e tipizzata dei dati comunicati. -
Operation
: una descrizione astratta di un'azione supportata dal servizio. -
Port Type
: un insieme astratto di operazioni supportate da uno o più endpoint. -
Binding
: un protocollo concreto e una specifica del formato dei dati per un particolare tipo di porta. -
Port
: un singolo endpoint definito come una combinazione di un'associazione e un indirizzo di rete. -
Service
: una raccolta di endpoint correlati.
Elemento | Descrizione |
---|---|
<tipi> | Definisce i tipi di dati (XML Schema) utilizzati dal servizio Web |
<messaggio> | Definisce gli elementi di dati per ciascuna operazione |
<tipoporta> | Descrive le operazioni che possono essere eseguite ei messaggi coinvolti. |
<vincolo> | Definisce il protocollo e il formato dei dati per ogni tipo di porta |
Esempio: richiesta/risposta SOAP 1.1 tramite HTTP
Esempio di documento WSDL XML.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
<? xml version = "1.0" ?> < definitions name = "StockQuote" targetNamespace = "http://example.com/stockquote.wsdl" xmlns : tns = "http://example.com/stockquote.wsdl" xmlns : xsd1 = "http://example.com/stockquote.xsd" xmlns : soap = "http://schemas.xmlsoap.org/wsdl/soap/" xmlns = "http://schemas.xmlsoap.org/wsdl/" > < types > < schema targetNamespace = "http://example.com/stockquote.xsd" xmlns = "http://www.w3.org/2000/10/XMLSchema" > < element name = "TradePriceRequest" > < complexType > < all > < element name = "tickerSymbol" type = "string" / > < / all > < / complexType > < / element > < element name = "TradePrice" > < complexType > < all > < element name = "price" type = "float" / > < / all > < / complexType > < / element > < / schema > < / types > < message name = "GetLastTradePriceInput" > < part name = "body" element = "xsd1:TradePriceRequest" / > < / message > < message name = "GetLastTradePriceOutput" > < part name = "body" element = "xsd1:TradePrice" / > < / message > < portType name = "StockQuotePortType" > < operation name = "GetLastTradePrice" > < input message = "tns:GetLastTradePriceInput" / > < output message = "tns:GetLastTradePriceOutput" / > < / operation > < / portType > < binding name = "StockQuoteSoapBinding" type = "tns:StockQuotePortType" > < soap : binding style = "document" transport = "http://schemas.xmlsoap.org/soap/http" / > < operation name = "GetLastTradePrice" > < soap : operation soapAction = "http://example.com/GetLastTradePrice" / > < input > < soap : body use = "literal" / > < / input > < output > < soap : body use = "literal" / > < / output > < / operation > < / binding > < service name = "StockQuoteService" > < documentation > My first service < / documentation > < port name = "StockQuotePort" binding = "tns:StockQuoteBinding" > < soap : address location = "http://example.com/stockquote" / > < / port > < / service > < / definitions > |

Esempio WSDL SOAP 2.0:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
< ! -- Crunchify ' s example of WSDL 2.0 -- > <? xml version = "1.0" encoding = "UTF-8" ?> < definitions xmlns = "http://www.w3.org/ns/wsdl" xmlns : tns = "http://www.tmsws.com/wsdl20sample" xmlns : whttp = "http://schemas.xmlsoap.org/wsdl/http/" xmlns : wsoap = "http://schemas.xmlsoap.org/wsdl/soap/" targetNamespace = "http://www.tmsws.com/wsdl20sample" > < ! -- Abstract type -- > < types > < xs : schema xmlns : xs = "http://www.w3.org/2001/XMLSchema" xmlns = "http://www.tmsws.com/wsdl20sample" targetNamespace = "http://crunchify.com/wsdl20" > < xs : element name = "request" > . . . add your code here . . . < / xs : element > < xs : element name = "response" > . . . add your code here . . . < / xs : element > < / xs : schema > < / types > < ! -- Abstract interfaces -- > < interface name = "CrunchifyItem" > < fault name = "ErrorDescription" element = "tns:response" / > < operation name = "Get" pattern = "http://www.w3.org/ns/wsdl/in-out" > < input messageLabel = "In" element = "tns:request" / > < output messageLabel = "Out" element = "tns:response" / > < / operation > < / interface > < ! -- Concrete Binding Over HTTP -- > < binding name = "HttpBinding" interface = "tns:CrunchifyItem" type = "http://www.w3.org/ns/wsdl/http" > < operation ref = "tns:Get" whttp : method = "GET" / > < / binding > < ! -- Concrete Binding with SOAP -- > < binding name = "SoapBinding" interface = "tns:CrunchifyItem" 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" / > < / binding > < ! -- Web Service offering endpoints for both bindings -- > < service name = "ServiceOne" interface = "tns:CrunchifyItem" > < endpoint name = "HttpEndpoint" binding = "tns:HttpBinding" address = "http://www.example.com/rest/" / > < endpoint name = "SoapEndpoint" binding = "tns:SoapBinding" address = "http://crunchify.com/soap/" / > < / service > < / definitions > |
Modello di progettazione di fabbrica spiegato con l'esempio.

Fatemi sapere se avete domande.