210 likes | 389 Views
WSDL. Web Services Description Language. Provides a model and an XML format for the “contract” of a web service Separates abstract service description from both concrete network protocol and message format Describes data types used in messages
E N D
Web Services Description Language • Provides a model and an XML format for the “contract” of a web service • Separates abstract service description from both concrete network protocol and message format • Describes data types used in messages • Messages are defined as aggregation of typed parts • Operations are message exchange patterns supported by the web service • PortTypes are named collections of operations
WSDL: More Basics • Define services as collections of network endpoints or ports • Messages are abstract descriptions of data being exchanged • Port types are abstraction collection of operations • Concrete protocol and data format specification for a particular porttype constitutes a binding
WSDL Components • Types– a container for data type definitions using some type system • Message– an abstract, typed definition of the data being communicated. • Operation– an abstract description of an action supported by the service. • Port Type–an abstract set of operations supported by one or more endpoints. • Binding– a concrete protocol and data format specification for a particular port type • Port– a single endpoint defined as a combination of a binding and a network address. • Service– a collection of related endpoints.
WSDL Specification types message message message porttype operation operation operation binding service port
An Example - WSDL Types <?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://schems.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>
WSDL Operations <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>
WSDL Bindings, Services, Ports <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>
More on Messages • Messages consist of one or more logical parts • Each part is associated with a type <definitions .... > <message name="nmtoken"> * <part name="nmtoken" element="qname"? type="qname"?/> * </message> </definitions>
More on Messages • Multiple part elements are used if the message has multiple logical units • Abstract vs. Concrete messages • Message definitions are abstract • Message binding describes how the abstract content is mapped to a concrete format • Bindings may provide very limited information is they are close
Operations • WSDL has four transmission primitives that an endpoint can support • One-way • Request-Response • Solicit Response • Notification • These primitives are referred to as operations
Operations <wsdl:definitions .... > <wsdl:portType .... > * <wsdl:operation name="nmtoken" parameterOrder="nmtokens"> <wsdl:input name="nmtoken"? message="qname"/><wsdl:output name="nmtoken"? message="qname"/><wsdl:fault name="nmtoken" message="qname"/>* </wsdl:operation> </wsdl:portType > </wsdl:definitions>
Port Types • A port type is a named set of abstract operations and abstract messages
WSDL Binding • maps the abstract service functionality to a specific network protocol and message format • defines: • the communication protocol to use • how service interactions are accomplished using this protocol • the address to communicate with • Three bindings are defined in the WSDL spec: • SOAP binding – HTTP binding • SMTP binding
WSDL Binding Example:One-way Over SMTP • <message name="SubscribeToQuotes"> <part name="body" element="xsd1:SubscribeToQuotes"/> • <part name="subscribeheader" element="xsd1:SubscriptionHeader"/> • </message> • <portType name="StockQuotePortType"> • <operation name="SubscribeToQuotes"> • <input message="tns:SubscribeToQuotes"/> • </operation> • </portType> • <binding name="StockQuoteSoap" type="tns:StockQuotePortType"> • <soap:binding style="document" transport="http://example.com/smtp"/> • <operation name="SubscribeToQuotes"> • <input message="tns:SubscribeToQuotes"> • <soap:body parts="body" use="literal"/> • <soap:header message="tns:SubscribeToQuotes" part="subscribeheader" use="literal"/> • </input> • </operation> • </binding> • <service name="StockQuoteService"> • <port name="StockQuotePort" binding="tns:StockQuoteSoap"> • <soap:address location="mailto:subscribe@example.com"/> • </port> • </service>
Request-Response RPC Over HTTP <binding name="StockQuoteSoapBinding" type="tns:StockQuotePortType"> • <soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/> • <operation name="GetTradePrice"> • <soap:operation soapAction="http://example.com/GetTradePrice"/> • <input> <soap:body use="encoded" namespace="http://example.com/stockquote" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/> • </input> • <output> <soap:body use="encoded" namespace="http://example.com/stockquote" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/> • </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>
Google’s WSDL Messages <message name="doGetCachedPage"> <part name="key" type="xsd:string" /> <part name="url" type="xsd:string" /> </message> <message name="doGetCachedPageResponse"> <part name="return" type="xsd:base64Binary" /> </message> <message name="doSpellingSuggestion"> <part name="key" type="xsd:string" /> <part name="phrase" type="xsd:string" /> </message> <message name="doSpellingSuggestionResponse"> <part name="return" type="xsd:string" /> </message> <message name="doGoogleSearch"> <part name="key" type="xsd:string" /> <part name="q" type="xsd:string" /> <part name="start" type="xsd:int" /> <part name="maxResults" type="xsd:int" /> <part name="filter" type="xsd:boolean" /> <part name="restrict" type="xsd:string" /> <part name="safeSearch" type="xsd:boolean" /> <part name="lr" type="xsd:string" /> <part name="ie" type="xsd:string" /> <part name="oe" type="xsd:string" /> </message> <message name="doGoogleSearchResponse"> <part name="return" type="typens:GoogleSearchResult" /> </message>
Google’s PortType <portType name="GoogleSearchPort"> <operation name="doGetCachedPage"> <input message="typens:doGetCachedPage" /> <output message="typens:doGetCachedPageResponse"/> </operation> <operation name="doSpellingSuggestion"> <input message="typens:doSpellingSuggestion"/> <output message="typens:doSpellingSuggestionResponse"/> </operation> <operation name="doGoogleSearch"> <input message="typens:doGoogleSearch"/> <output message="typens:doGoogleSearchResponse"/> </operation> </portType>
Google Bindings and Endpoint <binding name="GoogleSearchBinding" type="typens:GoogleSearchPort"> <soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http" /> <operation name="doGoogleSearch"> <soap:operation soapAction="urn:GoogleSearchAction" /> <input> <soap:body use="encoded" namespace="urn:GoogleSearch" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" /> </input> <output> <soap:body use="encoded" namespace="urn:GoogleSearch" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" / </output> </operation> </binding> <service name="GoogleSearchService"> <port name="GoogleSearchPort“ binding="typens:GoogleSearchBinding"> <soap:address location=http://api.google.com/search/beta2/> </port> </service>
Google Search Request <soap:Envelope xmlns:mrns0="urn:GoogleSearch" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <soap:Body soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"> <mrns0:doGoogleSearch> <key xsi:type="xs:string">XXrPsWdQFHKLrnHP5BRLENvY9mRSoAsI</key> <q xsi:type="xs:string">Java SOAP</q> <start xsi:type="xs:int">0</start> <maxResults xsi:type="xs:int">10</maxResults> <filter xsi:type="xs:boolean">false</filter> <restrict xsi:type="xs:string" /> <safeSearch xsi:type="xs:boolean">false</safeSearch> <lr xsi:type="xs:string" /> <ie xsi:type="xs:string" /> <oe xsi:type="xs:string" /> </mrns0:doGoogleSearch> </soap:Body> </soap:Envelope>
Search Response <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance" xmlns:xsd="http://www.w3.org/1999/XMLSchema"> <SOAP-ENV:Body> <ns1:doGoogleSearchResponse SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns1="urn:GoogleSearch"> <return xsi:type="ns1:GoogleSearchResult"> <resultElements xsi:type="ns3:Array" ns3:arrayType="ns1:ResultElement[10]" xmlns:ns3="http://schemas.xmlsoap.org/soap/encoding/"> <item xsi:type="ns1:ResultElement"> URL xsi:type="xsd:string">http://www-106.ibm.com/developerworks/xml/library/x-soapcl/</URL> <snippet xsi:type="xsd:string">This article describes a simple, general purpose <b>SOAP</b> client in <b>Java</b> that uses<br> no specialized <b>SOAP</b> libraries. <b>...</b> A general-purpose <b>Java</b> <b>SOAP</b> client <b>...</b> </snippet> <summary xsi:type="xsd:string" /> <title xsi:type="xsd:string">A simple <b>SOAP</b> client</title> </item> </resultElements> </return> </ns1:doGoogleSearchResponse> </SOAP-ENV:Body> </SOAP-ENV:Envelope>