340 likes | 564 Views
WSDL. Kanda Runapongsa ( krunapon@kku.ac.th ) Dept. of Computer Engineering Khon Kaen University. What is WSDL?. WSDL: Web Services Description Language A document format for precisely describing Web services A WSDL document tells us how to use a Web service. A WSDL Code Generator.
E N D
WSDL Kanda Runapongsa (krunapon@kku.ac.th) Dept. of Computer Engineering Khon Kaen University
What is WSDL? • WSDL: Web Services Description Language • A document format for precisely describing Web services • A WSDL document tells us how to use a Web service 168493: XML and Web Services (II/2546)
A WSDL Code Generator • WSDL is well suited for code generators, which can read a WSDL document and generate a programmatic interface for accessing a Web service • Example: a JAX-RPC provider uses WSDL 1.1 to generate Java RMI interfaces and network stubs, which can be used to exchange SOAP messages with a Web service 168493: XML and Web Services (II/2546)
A WSDL Code Generator • JAX-RPC is not the only technology that can generate interfaces and network stubs from WSDL document • There are many other code generators, including tools in • Microsoft .NET • Apace Axis 168493: XML and Web Services (II/2546)
A WSDL Code Generator • A JAX-RPC toolkit would use a WSDL document to generate a Java RMI interface (an endpoint interface) and a networking stub that implements the interface • What is Java RMI? 168493: XML and Web Services (II/2546)
JAVA RMI • RMI: Remote Method Invocation • Java-based technology which allows Java programs to access the objects of another Java program running on a different computer • RMI is a relatively simple protocol, but unlike more complex protocols such as CORBA and DCOM, it works only with Java objects 168493: XML and Web Services (II/2546)
Main Pieces of Info in WSDL • WSDL definition contains four important pieces of information about the Web service • Interface information describing all the publicly available functions • Data type information for the incoming (request) and outgoing (response) message to these functions 168493: XML and Web Services (II/2546)
Main Pieces of Info in WSDL • Two other important pieces of information about the Web service • Binding information about the protocol to be used for invoking the specified Web service • Address information for locating the specified Web service 168493: XML and Web Services (II/2546)
A WSDL Document • A WSDL document contains seven important elements • types • import • message • portType • operations • binding • service • These elements are nested in definitions element 168493: XML and Web Services (II/2546)
WSDL Important Elements • types • Use the XML schema language to declare complex data types and elements that are used elsewhere in the WSDL document • import • Similar to an import element in an XML schema document; it’s used to import WSDL definitions from other WSDL documents 168493: XML and Web Services (II/2546)
WSDL Important Elements • message • Describe the message’s payload using • XML schema built-in types • Complex types, or elements that are defined in the WSDL document’s types elements • Elements defined in an external WSDL document the import element refers to 168493: XML and Web Services (II/2546)
WSDL Important Elements • portType and operation • Describe a Web service’s interface and define its methods • A portType and its operation elements are analogous to a Java interface and its method declarations • An operation element uses one or more message types to define its input and output payloads 168493: XML and Web Services (II/2546)
WSDL Important Elements • binding • Assign a portType and its operation to a particular protocol (for instance, SOAP 1.1) and encoding style • service • Responsible for assigning an Internet address to a specific binding 168493: XML and Web Services (II/2546)
WSDL Declarations • The XML Declaration • The XML declaration in the sample WSDL document specified a character encoding of UTF-8 <?xml version=“1.0” encoding=“UTF-8”?> • A WSDL document must use either UTF-8 or UTF-16 encoding; other encoding systems are not allowed 168493: XML and Web Services (II/2546)
The definitions Element • The root element of all WSDL elements is the definitions element <definitions name=“BookQuoteWS” targetNamespace=“http://www.Monson-Haefel.com/jwsbook/BookQuote” xmlns:mh=“http://www.Monson-Haefel.com/jwsbook/BookQuote” xmlns:soapbind=“http://schemas.xmlsoap.org/wsdl/soap/” xmlns:xsd=“http://www.w3.org/2001/XMLSchema” xmlns=“http://schemas.xmlsoap.org/wsdl/”> 168493: XML and Web Services (II/2546)
The types Element • WSDL adopts the W3C XML schema built-in types • The types element serves as a container for defining any data types that are not described by the XML schema built-in types • The data types and elements defined in types element are used by message definitions 168493: XML and Web Services (II/2546)
Using Types Defined in the WSDL types <definitions … xmlns:mh=http://abc.com/BQuote” xmlns=“http://schemas.xmlsoap.org/wsdl”/> <types> <xsd:schema targetnamespace=“http://abc.com/BQuote”> <xsd:simpleType name=“ISBN”> … </xsd:simpleType>…</types> <message name=“GetBookPriceRequest”> <part name=“isbn” type=“mh:ISBN”/> </message> … </definitions> 168493: XML and Web Services (II/2546)
The import Element • The import element makes available in the present WSDL document the definition from a specified namespace in another WSDL document • Example, your company may want to maintain WSDL documents for shipping and order processing separately, but present a complete definition of all Web services in a public directory accessible by business partners 168493: XML and Web Services (II/2546)
The import Element Example <definitions name=“AllMhWebServices” xmlns=“http://schemas.xmlsoap.org/wsdl/”> <import namespace=“http://www.mh.com/jwsbook/BookQuote” location=“http://www.mh.com/jwsbook/BookPrice.wsdl”/> <import namespace=“http://www.mh.com/jwsbook/po” location=“http://www.mh.com/jwsbook/PurchaseOrder.wsdl”/> <import namespace=“http://www.mh.com/jwsbook/shipping” location=“http://www.mh.com/jwsbook/wsdl/Shipping.wsdl”/> 168493: XML and Web Services (II/2546)
The message Element • The message element describes the payload of a message used by a Web service • The way to define a message element depends on whether you use RPC-style or document-style messaging 168493: XML and Web Services (II/2546)
The message Element for RPC-Style <message name=“GetBookPriceRequest”> <part name=“isbn” type=“xsd:string”/> </message> <message name=“GetBookPriceResponse”> <part name=“price” type=“xsd:float”> </message> 168493: XML and Web Services (II/2546)
The message Element for Document-Style <definitions … xmlns:mh=“http://www.mh.com/jwsbook/PO”> <types> <xsd:schema targetNamespace=“http://www.mh.com/jwsbook/PO”> <xsd:import namespace=“http://www.mh.com/jwsbook/PO” schemaLocation=“http://www.mh.com/jwsbook/po.xsd”/> </xsd:schema> </types> <message name=“SubmitPurchaseOrderMessage”> <part name=“order” element=“mh:purchaseOrder”/> </message> 168493: XML and Web Services (II/2546)
The portType Element • A portType element defines the abstract interface of a Web service • It’s a lot like a Java interface because it defines an abstract type and its method, but not an implementation • In WSDL, the portType is implemented by the binding and service elements 168493: XML and Web Services (II/2546)
portType <portType name=“BookQuote”> <operation name=“GetBookPrice”> <input name=“isbn” …/> <output name=“price” …/> </operation> </portType> Java Interface public interface bookQuote { public float getBookPrice(String isbn); } portType and Java Interface 168493: XML and Web Services (II/2546)
The operation Element • The “methods” of the portType are its operation elements • A portType may have one or more operation elements, each of which defines an RPC- or document-style Web service method • Each operation is composed of input , output, and fault elements 168493: XML and Web Services (II/2546)
The operation Element Example <portType name=“BookQuote”> <operation name=“getBookPrice”> <input name=“isbn” message=“mh:GetBookPriceRequest”/> <output name=“price” message=“mh:GetBookPriceResponse”/> <fault name=“InvalidArgumentFault” message=“mh:InvalidArgumentFault”/> </operation> </portType> 168493: XML and Web Services (II/2546)
Parameter Order within an Operation <message name=“GetBulkBookPriceRequest”> <part name=“isbn” type=“xsd:string”/> <part name=“quantity” type=“xsd:int”/> </message> … <portType name=“GetBulkBookPrice”> <operation name=“getBulkBookPrice” parameterOrder=“isbn quantity”> <input name=“request” message=“GetBulkBookPriceRequest”/> … </portType> 168493: XML and Web Services (II/2546)
The binding Element • The binding element maps an abstract portType to a set of concrete protocols such as SOAP and HTTP, messaging styles (RPC or document), and encoding styles (Literal or SOAP Encoding) • The binding element and its subelements are used in combination with protocol-specific elements 168493: XML and Web Services (II/2546)
The binding Element <definitions … xmlns=“http://schemas.xmlsoap.org/wsdl/”> <binding name=“BookPrice_Binding” type=“mh:BookQuote”> … <operation> <input> <output> </operation> </binding> 168493: XML and Web Services (II/2546)
The binding Element <definitions … xmlns:soapbind=“http://schemas.xmlsoap.org/wsdl/soap”> <binding name=“BookPrice_Binding” type=“mh:BookQuote”> <soapbind:binding style=“rpc” transport=“http://schemas.xmlsoap.org/soap/http”/> 168493: XML and Web Services (II/2546)
The binding Element <operation name=“getBookprice”> <soapbind:operation style=“rpc” soapAction=“http://www.mh.com/jwsbook/BookQuote/GetBookPrice”/> <input> <soapbind:body use=“literal” namespace=“http://www.mh.com/jwsbook/BookQuote”/> 168493: XML and Web Services (II/2546)
The service and port Elements • The service element contains one or more port elements, each of which represents a different Web service • The port element assigns the URL to a specific binding • A service may have more than one port element, each of which assigns a URL to a specific binding 168493: XML and Web Services (II/2546)
Defining a service Element <service name=“BookPriceService”> <port name=“BookPrice_Port binding=“mh:BookPrice_Binding”> <soapbind:address location=http://www.mh.com/jwsbook/BookQuote/> </port> </service> 168493: XML and Web Services (II/2546)