Înțelegerea de bază a structurii WSDL – (Limbajul de descriere a serviciului web) explicată
Publicat: 2020-08-24Poate că ați văzut postarea mea anterioară despre apelul SOAP vs. REST. Acum, companiile trec la apelurile de serviciu REST, dar totuși, majoritatea companiilor încă folosesc SOAP în detrimentul REST. Acest tutorial explică elementele de bază ale WSDL (Web Service Description Language).
Dacă aveți oricare dintre întrebările de mai jos, vă aflați la locul potrivit:
- Ce este limbajul de descriere a serviciilor web (WSDL)?
- Tutorial WSDL
- Limbajul de descriere a serviciilor web (WSDL) Explicat
- Exemple de WSDL – Web Service Description Language
Limbajul de descriere a serviciilor web (WSDL)
În Java Web Development World, WSDL este un format XML pentru a descrie serviciile de rețea ca un set de puncte finale care operează pe mesaje care conțin informații fie orientate pe documente, fie pe proceduri.
Operațiunile și mesajele sunt descrise în mod abstract și apoi legate la un protocol de rețea concret și la un format de mesaj pentru a defini un punct final. Punctele finale concrete înrudite sunt combinate în puncte finale abstracte (servicii).
WSDL este extensibil pentru a permite descrierea punctelor finale și a mesajelor acestora, indiferent de formatele de mesaje sau protocoalele de rețea folosite pentru a comunica, cu toate acestea, singurele legături descrise în acest document descriu cum să utilizați WSDL
împreună cu SOAP 1.1, HTTP GET/POST și MIMA.

Altul trebuie să citească:
- Creați un exemplu de WSDL în Eclipse și generați client
- Cum să construiți un serviciu RESTful cu Java folosind JAX-RS și Jersey (Exemplu)
Cu alte cuvinte: un document WSDL definește serviciile ca colecții de puncte finale de rețea sau ports
. În WSDL, definiția abstractă a punctelor finale și a mesajelor este separată de implementarea lor concretă în rețea sau de legăturile de format de date. Acest lucru permite reutilizarea definițiilor abstracte: messages
, care sunt descrieri abstracte ale datelor care sunt schimbate și tipuri de porturi care sunt colecții abstracte de operațiuni.
Protocolul concret și specificațiile de format de date pentru un anumit tip de port constituie o binding
reutilizabilă. Un port este definit prin asocierea unei adrese de rețea cu o legare reutilizabilă, iar o colecție de porturi definește un serviciu.
Prin urmare, un document WSDL utilizează următoarele elemente în definirea serviciilor de rețea:
-
Types
– un container pentru definițiile tipurilor de date folosind un sistem de tip (cum ar fiXSD
). -
Message
– o definiție abstractă, tipărită, a datelor care sunt comunicate. -
Operation
– o descriere abstractă a unei acțiuni susținute de serviciu. -
Port Type
– un set abstract de operațiuni suportate de unul sau mai multe puncte finale. -
Binding
– un protocol concret și o specificație de format de date pentru un anumit tip de port. -
Port
– un singur punct final definit ca o combinație între o legătură și o adresă de rețea. -
Service
– o colecție de puncte finale asociate.
Element | Descriere |
---|---|
<tipuri> | Definește tipurile de date (schema XML) utilizate de serviciul web |
<mesaj> | Definește elementele de date pentru fiecare operațiune |
<portType> | Descrie operațiunile care pot fi efectuate și mesajele implicate. |
<legare> | Definește protocolul și formatul de date pentru fiecare tip de port |
Exemplu: SoAP 1.1 Solicitare/Răspuns prin HTTP
Exemplu de document XML WSDL.
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 > |

Exemplu 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 > |
Modelul de proiectare a fabricii explicat cu Exemplu.

Anunțați-mă dacă aveți întrebări.