XML WSDL
- WSDL znamená jazyk popisu webových služeb
- WSDL se používá k popisu webových služeb
- WSDL je napsán v XML
- WSDL je doporučení W3C z 26. června 2007
Dokumenty WSDL
Dokument WSDL popisuje webovou službu. Specifikuje umístění služby a metody služby pomocí těchto hlavních prvků:
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 |
Hlavní struktura dokumentu WSDL vypadá takto:
<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>
Příklad WSDL
Toto je zjednodušený zlomek 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>
V tomto příkladu element <portType> definuje "glossaryTerms" jako název portu a "getTerm" jako název operace .
Operace "getTerm" má vstupní zprávu nazvanou "getTermRequest" a výstupní zprávu nazvanou "getTermResponse".
Prvky <message> definují části každé zprávy a související datové typy.
Element <portType>
Prvek <portType> definuje webovou službu , operace , které lze provádět, a související zprávy .
Typ požadavek-odpověď je nejběžnějším typem operace, ale WSDL definuje čtyři 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 |
Jednosměrný provoz WSDL
Příklad jednosměrné operace:
<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 >
Ve výše uvedeném příkladu portType "glossaryTerms" definuje jednosměrnou operaci nazvanou "setTerm".
Operace "setTerm" umožňuje vkládat zprávy nových glosářských termínů pomocí zprávy "newTermValues" se vstupními parametry "term" a "value". Pro operaci však není definován žádný výstup.
Operace požadavek-odpověď WSDL
Příklad operace požadavek-odpověď:
<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>
Ve výše uvedeném příkladu portType "glossaryTerms" definuje operaci žádost-odpověď nazvanou "getTerm".
Operace "getTerm" vyžaduje vstupní zprávu nazvanou "getTermRequest" s parametrem nazvaným "term" a vrátí výstupní zprávu s názvem "getTermResponse" s parametrem nazvaným "value".
Vazba WSDL na SOAP
Vazby WSDL definují formát zprávy a podrobnosti protokolu pro webovou službu.
Příklad operace požadavek-odpověď:
<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>
Vazebný prvek má dva atributy – název a typ.
Atribut name (můžete použít libovolný název) definuje název vazby a atribut type ukazuje na port pro vazbu, v tomto případě na port "glossaryTerms".
Element soap:binding má dva atributy – styl a transport.
Atribut stylu může být „rpc“ nebo „document“. V tomto případě použijeme dokument. Atribut transport definuje protokol SOAP, který se má použít. V tomto případě používáme HTTP.
Element Operation definuje každou operaci, kterou portType zpřístupňuje.
Pro každou operaci musí být definována odpovídající akce SOAP. Musíte také určit, jak jsou kódovány vstup a výstup. V tomto případě používáme „doslovný“.