XML WSDL
- WSDL oznacza język opisu usług internetowych
- WSDL służy do opisu usług internetowych
- WSDL jest napisany w XML
- WSDL jest rekomendacją W3C od 26. czerwca 2007
Dokumenty WSDL
Dokument WSDL opisuje usługę sieciową. Określa lokalizację usługi oraz metody jej świadczenia, wykorzystując następujące główne elementy:
Element | Description |
---|---|
<types> | Defines the (XML Schema) data types used by the web service |
<message> | Defines the data elements for each operation |
<portType> | Describes the operations that can be performed and the messages involved. |
<binding> | Defines the protocol and data format for each port type |
Główna struktura dokumentu WSDL wygląda tak:
<definitions>
<types>
data type definitions........
</types>
<message>
definition of the data being communicated....
</message>
<portType>
set of operations......
</portType>
<binding>
protocol and data format specification....
</binding>
</definitions>
Przykład WSDL
To jest uproszczona część dokumentu WSDL:
<message name="getTermRequest">
<part name="term" type="xs:string"/>
</message>
<message name="getTermResponse">
<part name="value" type="xs:string"/>
</message>
<portType name="glossaryTerms">
<operation name="getTerm">
<input message="getTermRequest"/>
<output message="getTermResponse"/>
</operation>
</portType>
W tym przykładzie element <portType> definiuje „glossaryTerms” jako nazwę portu i „getTerm” jako nazwę operacji .
Operacja „getTerm” zawiera komunikat wejściowy o nazwie „getTermRequest” i komunikat wyjściowy o nazwie „getTermResponse”.
Elementy <message> definiują części każdej wiadomości i skojarzone typy danych.
Element <portType>
Element <portType> definiuje usługę sieci Web , operacje , które można wykonać, oraz zaangażowane komunikaty .
Typ żądanie-odpowiedź jest najczęstszym typem operacji, ale WSDL definiuje cztery typy:
Type | Definition |
---|---|
One-way | The operation can receive a message but will not return a response |
Request-response | The operation can receive a request and will return a response |
Solicit-response | The operation can send a request and will wait for a response |
Notification | The operation can send a message but will not wait for a response |
Operacja jednokierunkowa WSDL
Przykład działania w jedną stronę:
<message name="newTermValues">
<part name="term" type="xs:string"/>
<part name="value" type="xs:string"/>
</message>
<portType name="glossaryTerms">
<operation name="setTerm">
<input name="newTerm" message="newTermValues"/>
</operation>
</portType >
W powyższym przykładzie portType „glossaryTerms” definiuje operację jednokierunkową o nazwie „setTerm”.
Operacja "setTerm" umożliwia wprowadzanie nowych komunikatów terminów słownikowych za pomocą komunikatu "newTermValues" z parametrami wejściowymi "term" i "value". Jednak żadne dane wyjściowe nie są zdefiniowane dla operacji.
Operacja żądanie-odpowiedź WSDL
Przykład operacji żądanie-odpowiedź:
<message name="getTermRequest">
<part name="term" type="xs:string"/>
</message>
<message name="getTermResponse">
<part name="value" type="xs:string"/>
</message>
<portType name="glossaryTerms">
<operation name="getTerm">
<input message="getTermRequest"/>
<output message="getTermResponse"/>
</operation>
</portType>
W powyższym przykładzie portType „glossaryTerms” definiuje operację żądanie-odpowiedź o nazwie „getTerm”.
Operacja „getTerm” wymaga komunikatu wejściowego o nazwie „getTermRequest” z parametrem o nazwie „term” i zwróci komunikat wyjściowy o nazwie „getTermResponse” z parametrem o nazwie „value”.
Powiązanie WSDL z SOAP
Powiązania WSDL definiują format komunikatu i szczegóły protokołu dla usługi WWW.
Przykład operacji żądanie-odpowiedź:
<message name="getTermRequest">
<part name="term" type="xs:string"/>
</message>
<message name="getTermResponse">
<part name="value" type="xs:string"/>
</message>
<portType name="glossaryTerms">
<operation name="getTerm">
<input message="getTermRequest"/>
<output message="getTermResponse"/>
</operation>
</portType>
<binding type="glossaryTerms" name="b1">
<soap:binding style="document"
transport="http://schemas.xmlsoap.org/soap/http" />
<operation>
<soap:operation
soapAction="http://example.com/getTerm"/>
<input><soap:body use="literal"/></input>
<output><soap:body use="literal"/></output>
</operation>
</binding>
Element bindujący ma dwa atrybuty — nazwę i typ.
Atrybut name (możesz użyć dowolnej nazwy) definiuje nazwę powiązania, a atrybut type wskazuje na port powiązania, w tym przypadku na port „glossaryTerms”.
Element soap:binding ma dwa atrybuty - styl i transport.
Atrybutem stylu może być „rpc” lub „dokument”. W tym przypadku korzystamy z dokumentu. Atrybut transportu definiuje używany protokół SOAP. W tym przypadku korzystamy z protokołu HTTP.
Element operation definiuje każdą operację, którą uwidacznia portType.
Dla każdej operacji należy zdefiniować odpowiednią akcję SOAP. Należy również określić sposób kodowania danych wejściowych i wyjściowych. W tym przypadku używamy „dosłownego”.