180 likes | 344 Views
Web Services: WSDL. Kas ir WSDL ?. Pirms izmantot SOAP ar konkrēto servisu ir jāzina kādai jābūt SOAP ziņojuma struktūrai kuru protokolu izmantot (HTTP, SMTP u.c. ) kāda ir web servisa Internet adrese
E N D
Kas ir WSDL? • Pirms izmantot SOAP ar konkrēto servisu ir jāzina • kādai jābūt SOAP ziņojuma struktūrai • kuru protokolu izmantot (HTTP, SMTP u.c.) • kāda ir web servisa Internet adrese • WSDL (Web Services Description Language) ir XML tipa valoda, kas apraksta Web servisus un to kā tiem piekļūt • WSDL 1.1 – 2001.gada 15.marts • WSDL 2.0 –2007.gada 26.jūnijs
Ko WSDL definē? • WSDL describes four critical pieces of data • Interface information describing all publicly available functions • Data type information for all message requests and message responses • Binding information about the transport protocol to be used • Address information for locating the specified service • WSDL represents a contract between the service requestor and the service provider
WSDL Code Generation • WSDL is well suited for code generators, which can read a WSDL document and generate a programmatic interface for accessing a Web service
WSDL 1.1 Specification • The full specification is divided into six major elements • definitions • types • message • portType • binding • service
The definitions Element • Root element of all WSDL documents • Defines the name of the web service • Declares multiple namespaces used throughout the document • Contains all other the service elements <definitions name="BookQuoteWS" targetNamespace="http://www.Monson-Haefel.com/jws/BookQuote" xmlns:mh="http://www.Monson-Haefel.com/jws/BookQuote" xmlns:soapbind="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.xmlsoap.org/wsdl/"> . . . . . . </definitions>
The types Element • Describes all the data types used between the client and server • Uses the XML schema language to declare complex data types and elements • WSDL adopts, as its basic type system, the W3C XML schema built-in types • If the service uses only W3C XML Schema built-in simple types, such as strings and integers, the types element is not required
Example: types element <types> <xsd:schema targetNamespace="http://www.Monson-Haefel.com/jwsbook/BookQuote"> <xsd:simpleType name="ISBN"> <xsd:restriction base="xsd:string"> <xsd:pattern value="[0-9]{9}[0-9Xx]" /> </xsd:restriction> </xsd:simpleType> </xsd:schema> </types>
The message Element • Describes a one-way message, whether it is a single message request or a single message response • Defines the name of the message • Contains zero or more message part elements, which can refer to message parameters or message return values
Example: message element <definitions name="BookPrice" ...> ... <message name="GetBookPriceRequest"> <part name="isbn" type="xsd:string" /> </message> <message name="GetBookPriceResponse"> <part name="price" type="xsd:float" /> </message> ... </definitions>
The portTypeElement • Combines multiple message elements to form a complete one-way or round-trip operation • Defines the abstract interface of a Web service <portType name="BookQuote"> <operation name="getBookPrice"> <input name="isbn" message="mh:GetBookPriceRequest"/> <output name="price" message="mh:GetBookPriceResponse"/> </operation> </portType>
Messaging Exchange Patterns • There are four basic message exchange patternsused in Web services • Request/Response • The service receives a message • One-Way • The service receives a message and sends a response • Notification • The service sends a message • Solicit/Response • The service sends a message and receives a response
The bindingElement • Describes the concrete specifics of how the service will be implemented on the wire • Maps an abstract portType to a set of concrete • protocols such as SOAP and HTTP • messaging styles (RPC or document) • encoding styles (Literal or SOAP Encoding)
Example: binding element <binding name="BookPrice_Binding" type="mh:BookQuote"> <soapbind:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/> <operation name="getBookPrice"> <soapbind:operation style="rpc" soapAction="http://… /BookQuote/GetBookPrice"/> <input> <soapbind:body use="literal" namespace="http://…/BookQuote" /> </input> <output> <soapbind:body use="literal" namespace="http://…/BookQuote" /> </output> </operation> </binding>
The serviceElement • Specifies the location of the service • Contains one or more port elements, each of which represents a different Web service • The port element assigns the URL to a specific binding <service name="BookPriceService"> <port name="BookPrice_Port" binding="mh:BookPrice_Binding"> <soapbind:address location= "http://www.Monson-Haefel.com/jwsbook/BookQuote" /> </port> </service>
WSDL 2.0 • Now there are 3 separate specifications • Part 1: Core • Abstract interfaces, independent ofprotocol and encoding • Part 2: Message Exchange Patterns • Predefined types of interactions • Part 3: Bindings • SOAP and HTTP/MIME binding
Summary • WSDL provides a precise, structured, and standard format for describing Web services • Code generators can create convenient language-specific call interfaces for invoking Web services • So, in many cases you will not deal directly with WSDL documents • You have to understand WSDL to construct and exchange SOAP messages properly when using SOAP APIs
References • WSDL Essentials http://www.oreilly.com/catalog/webservess/chapter/ch06.html • WSDL Version 2.0 Part 0: Primer http://www.w3.org/2002/ws/desc/wsdl20-primer • Google Search WSDL example http://api.google.com/GoogleSearch.wsdl