1 WSDL Tutorial Heather Kreger (borrowed from Peter Brittenham) Web Services Architect IBM Emerging Technologies
2 WSDL: Web Service Description Language Standard for describing Web services Abstract interface for defining operations and their messages Messages contain either document-oriented or procedure- oriented information Bindings to message formats and protocols Defines how to locate the endpoint for the service Example: URLs for HTTP Extensible (SOAP and HTTP extensions are defined) Written in XML, leverages XML schema WSDL V1.1 Specification
3 Usage Scenarios As IDL (Interface Definition Language) Allows tools to generate client access code for a service Examples: IBM WebSphere Studio Application Developer, IBM Web Services Toolkit Standardized service interface descriptions Allows advertisement and dynamic discovery of services Enables dynamic binding to service Complements UDDI registry
4 Document Content Abstract Definitions data type definitions operation parameters operation definitions Concrete Definitions operation bindings location/address for each binding Also: used to reference other XML documents
5 WSDL Extensibility Elements Extensibility elements can be specified within these WSDL elements: / / / Binding extensibility defined in the specification for: SOAP HTTP MIME
6 Document Structure [SOAP] [Request] [data] [Response] [EJB] […] Service(s) Supported Protocol(s) Java class method SOAP Request/ response
7 SOAP Binding - RPC Style Indicates that the Web service is accessed using SOAP V1.1 protocol Use style="rpc" attribute on SOAP binding element Example SOAP service method signature: public float getQuote (String symbol)
8 Example: Stock Quote Service [1] <definitions name="StockQuoteService" targetNamespace=" xmlns:tns=" …>... public float getQuote (String symbol)
9 Example: Stock Quote Service [2]... <soap:binding style="rpc" transport=" /> <soap:body use="encoded" namespace=" encodingStyle="
10 Example: Stock Quote Service [3] … Stock Quote Service -- <soap:address location=" />
11 Message Defines the messages that are referenced in the input, output, and fault elements within an operation A message may have one or more parts Each part contains a reference to a data type elementReference to XML Schema element using a QName typeReference to XML Schema simpleType or complexType *
12 PortType Contains one or more abstract operations Each operation references one or more messages Four operation types: One-waySend message to service and there is no response Request-responseSend message to service which returns a correlated message Solicit-responseService sends a message and requestor returns a correlated message NotificationService sends a message to the requestor
13 PortType One-way Operation Request-response Operation * * *
14 Binding Each binding has an unique name Referenced by a port element Contains a reference to one portType Binding interpreted based on ext. elements * ? ? * *
15 Service A WSDL document may contain one or more service elements Each service element may contain one or more ports A port is named, references one binding, and contains the endpoint for the Web service Port names must be unique within a service element Endpoint is specified using an extensibility element *
16 Complex Type Definitions Complex data types Defined within the element or by referencing an external XML schema document AddressBook Example: public void addEntry(String name, Address address)...
17 AddressBook Service <import location=" namespace=" </portType...
18 SOAP Binding - Document Style Similar to SOAP Binding with RPC Style SOAP binding contains style=“document” attribute This style can also be set on a SOAP body element which is specified with each operation element Used with Web services that specify XML documents for message content Example: UDDI Registry Business Name
19 WSDL for UDDI Registry [1] <definitions targetNamespace="urn:uddi-org:inquiry" xmlns:uddi="urn:uddi-org:api_v2" xmlns:tns="urn:uddi-org:inquiry_v2"...> <import namespace="urn:uddi-org:api" location=" />......
20 WSDL for UDDI Registry [2] <soap:binding style="document" transport=" /> <soap:body use="literal" parts="body" namespace="urn:uddi-org:api_v2" />...
21 MIME Binding Examples of supported MIME types: multipart/related text/xml application/x-www-form-urlencoded Input or output message can be defined using MIME binding MIME binding can be combined with SOAP binding to define a service that uses SOAP attachments Use multipart/related binding SOAP envelope must be in the root part Define other parts using MIME binding
22 Attachment Service Interface [1]...
23 Attachment Service Interface [2]...
24 Attachment Service Interface [3] <soap:body parts="fileList" use="encoded" namespace=" encodingStyle=" <soap:body use="encoded“ namespace=“ encodingStyle="
25 WSDL4J WSDL Java API WSDL object model Parse contents of a WSDL document Programmatically create new WSDL documents Open source project on IBM developerWorks site Will be a reference implementation for JSR 110 Primarily a set of Java interfaces that can be implemented by anyone Java package name: javax.wsdl
26 WSDL4J Example - Find Port // Get WSDLReader WSDLReader wsdlReader = WSDLFactory.newInstance().newWSDLReader(); // Read WSDL service implementation document Definition wsdlDefinition = wsdlReader.readWSDL(null, wsdlURL); // Get the service elements Map services = definition.getServices(); // Get an iterator for the list of services Iterator serviceIterator = services.values().iterator(); boolean bPortFound = false; while ((serviceIterator.hasNext()) && !(bPortFound)) { // Get next service element Service service = (Service) serviceIterator.next(); // Determine if this service element contains the specified port if ((port = service.getPort(portName)) != null) bPortFound = true; }
27 WSDL Resources WSDL V1.1 Specification W3C Web Services Description Working Group WSDL4J Open Source Project wsdl4j/ Yahoo Group: wsdl
28 An Overview of Web Services – Part 2 Questions?