Web Services WSDL What is WSDL Before using
Web Services: WSDL
What is WSDL? • Before using SOAP need to know: • • • expected structure of SOAP message which transport protocol to use (HTTP, SMTP etc) where the web service is located • WSDL (Web Services Description Language) is an XML standard describing Web Services and their physical implementation/addressing • WSDL 1. 1 – March 2001 • WSDL 2. 0 – June 2007
What does WSDL define? • 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 • port. Type • 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="Book. Quote. WS" target. Namespace="http: //www. Monson-Haefel. com/jws/Book. Quote" xmlns: mh="http: //www. Monson-Haefel. com/jws/Book. Quote" xmlns: soapbind="http: //schemas. xmlsoap. org/wsdl/soap/" xmlns: xsd="http: //www. w 3. 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 W 3 C XML schema built-in types • If the service uses only W 3 C XML Schema built -in simple types, such as strings and integers, the types element is not required
Example: types element <types> <xsd: schema target. Namespace="http: //www. Monson. Haefel. com/jwsbook/Book. Quote"> <xsd: simple. Type name="ISBN"> <xsd: restriction base="xsd: string"> <xsd: pattern value="[0 -9]{9}[0 -9 Xx]" /> </xsd: restriction> </xsd: simple. Type> </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="Book. Price". . . >. . . <message name="Get. Book. Price. Request"> <part name="isbn" type="xsd: string" /> </message> <message name="Get. Book. Price. Response"> <part name="price" type="xsd: float" /> </message>. . . </definitions>
The port. Type Element • Combines multiple message elements to form a complete one-way or round-trip operation • Defines the abstract interface of a Web service <port. Type name="Book. Quote"> <operation name="get. Book. Price"> <input name="isbn" message="mh: Get. Book. Price. Request"/> <output name="price" message="mh: Get. Book. Price. Response"/> </operation> </port. Type>
Messaging Exchange Patterns • There are four basic message exchange patterns used 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 binding Element • Describes the concrete specifics of how the service will be implemented on the wire • Maps an abstract port. Type 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="Book. Price_Binding" type="mh: Book. Quote"> <soapbind: binding style="rpc" transport="http: //schemas. xmlsoap. org/soap/http"/> <operation name="get. Book. Price"> <soapbind: operation style="rpc" soap. Action="http: //… /Book. Quote /Get. Book. Price"/> <input> <soapbind: body use="literal" namespace="http: //…/Book. Quote" /> </input> <output> <soapbind: body use="literal" namespace="http: //…/Book. Quote" /> </output> </operation> </binding>
The service Element • 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="Book. Price. Service"> <port name="Book. Price_Port" binding="mh: Book. Price_Binding"> <soapbind: address location= "http: //www. Monson-Haefel. com/jwsbook/Book. Quote" /> </port> </service>
WSDL 2. 0 • Now there are 3 separate specifications • Part 1: Core • Abstract interfaces, independent of protocol 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 languagespecific 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/chap ter/ch 06. html • WSDL Version 2. 0 Part 0: Primer http: //www. w 3. org/2002/ws/desc/wsdl 20 -primer • Google Search WSDL example http: //api. google. com/Google. Search. wsdl
- Slides: 18