WELCOME Abdennour : Software engineer

May 15, 2012

2.WSDL :Describe and configure & HelloWorld WSDL (Eclipse+SoapUI)


This tutorial of course is an introduction to WSDL used to describe and configure a Web Service extended. The Tutorial begins with a presentation of the abstract part of WSDL is used to describe the messages and operations. It is followed by a description of the portion used pure concrete protocol and describe the encoding to use for messages.


1.WSDL Generalities 
2.HelloWorld Service (WSDL for Example) 
3. Use SoapUI in Eclipse to Generate WS from WSDL : 
4.Type Element
5.Message Element :
6.PortType & Operation Element 
7.Binding Element 
8. SOAP Binding
9.Service & Port Element
10.Binding HTTP GET & Post :


1.WSDL Generalities : 
-WSDL : Web Service Description Language 
=> Based on XML langage and allow to describe a WS. 
-It provides an independent description of the language and platform .

 -If we have a WSDL  , We Can : 
>>Generate Client to call a Web Service
>>Generate Code to implement a Web Service . 
 Example of WSDL : 

Where is WSDL used ?

   WSDL Concepts:
      1.data : typed information
       2.message : a set of data . 
      3.operation : action provided by WS (~ method in java)
      4.port Type : set of action (~ interface in java)
      5.binding;: define for port type the protocol used to transmit informations & data format
      6.port:define where is the WS and where is the binding to use
       7.service : a set of ports
2.HelloWorld Service (WSDL for Example) :
-HelloWorld Service is a service which provides 2 operations :
   >>makeHello  : Param(String) , return(String)
   >>simpleHello  : Param(void) , return(String)
-Access to Service is performed by SOAP messages.
 -HTTP : Protocol used to exchange SOAP Messages.
 -Style used is RPC
=======================================





<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<definitions name="HelloWorld"
xmlns:tns="http://helloworldwebservice.lisi.ensma.fr/" xmlns:xsd="http://
<types />
<message name="makeHelloWorld">
<part name="value" type="xsd:string" />
</message>
<message name="makeHelloWorldResponse">
<part name="helloWorldResult" type="xsd:string" />
</message>
<message name="simpleHelloWorld" />
<message name="simpleHelloWorldResponse">
<part name="helloWorldResult" type="xsd:string" />
</message>
<portType name="HelloWorld">
<operation name="makeHelloWorld">
<input message="tns:makeHelloWorld" />
<output message="tns:makeHelloWorldResponse" />
</operation>
<operation name="simpleHelloWorld">
<input message="tns:simpleHelloWorld" />
<output message="tns:simpleHelloWorldResponse" />
</operation>
</portType>
<binding name="HelloWorldPortBinding" type="tns:HelloWorld">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http"
style="rpc" />
<operation name="makeHelloWorld">
<soap:operation soapAction="" />
<input>
<soap:body use="literal"
</input>
<output>
<soap:body use="literal"
</output>
</operation>
<operation name="simpleHelloWorld">
<soap:operation soapAction="" />
<input>
<soap:body use="literal"
</input>
<output>
<soap:body use="literal"
</output>
</operation>


</binding>
<service name="HelloWorld">
<port name="HelloWorldPort" binding="tns:HelloWorldPortBinding">
<soap:address location="TODO" />
</port>
</service>
</definitions>

=============================================================================

<definitions>: Root of WSDL Document .
i . Abstract Part :Describe available  Messages & Operations
<types >: [Optional & used once]include the definition of data types(xml schema).
<message>: Describe Message to transmit. (Operation Parameter , Operation Return,Exception ...
<portType>: Describe a set of Operations .(Input Messages , OutPut Messages or Fault)
ii . Concret Part :Describe Protocol used and the encoding to use for Messages
<binding>:links portType to protocol (SOAP,HTTP)
<service>: set of Port(Relation between binding & URL).
==> Utility of Separation : Reuse of Abstract Part . 





3. Use SoapUI in Eclipse to Generate WS from WSDL :


Step 0  : 
Download  SoapUI plugin for eclipse : 
  Online URL : 
  Offline URL : 

Step 1: Enable soapUI Nature
Start by creating an empty Java project and enabling the soapUI Nature from the projects popup menu: 
=>Follow this tuto , I want to go back to WSDL Description  : )

  4.Type Element
 -include definition of  Types used to describe messages .
  -If types is based-Types (Integer ,Boolean..) , Type element is optional in WSDL . 
    -Else if type is complex(Person ,..) ,  XML Schema is used .
EXAMPLE (<type>) :
<types>
<xsd:schema targetNamespace="http://notebookwebservice.lisi.ensma.fr/">
                               <xsd:complexType name="person">
                                     <xsd:sequence>
<xsd:element name="address" type="xs:stringminOccurs="0" />
                                                 <xsd:element name="birthyear" type="xs:stringminOccurs="0" />
                                                  <xsd:element name="name" type="xs:string" minOccurs="0" />
                                      </xsd:sequence>
   </xsd:complexType>
   <xsd:complexType name="personArray" final="#all">       <!-- TYPE ARRAY of  PERSON -->
        <xsd:sequence>
<xsd:element name="item" type="tns:person" minOccurs="0"
maxOccurs="unbounded" nillable="true
</xsd:sequence>
</xsd:complexType>
</xsd:schema>
</types>

====================================
-Address of Schema XML host and Address of WSDL host are not always the same . 
Importation of Schema XML in WSDL : 
<definitions ..> 
....
 <types>
          <xsd:schema>
                      <xsd:import namespace="http://notebookwebservice.lisi.ensma.fr schemaLocation="Notebook_schema1.xsd"/>
          </xsd:schema>
</types>
</definitions>
5.Message Element :
 -Used to describe messages (param , return , exception) .
  -Every Message has : 
                  1) Id :name ,
                     2) set of <part> (~ 1 part =>  1 parameter of operation ).
Examples : 
Message used to call an operation with one party
<message name="addPersonWithComplexType"><part name="newPerson" type="tns:person"/></message>
Message used to calling a procedure with three parts
<message name="addPersonWithSimpleType">
<part name="name" type="xsd:string"/>
<part name="address" type="xsd:string"/>
<part name="birthyear" type="xsd:string"/>
</message>

Part that points to a type defined by the element <types>
<message name="getPersonResponse">
<part name="getPersonResult" type="tns:person"/>
</message>


6.PortType & Operation Element 
 -<portType>  has : 
       1)id : name=".."
        2)subElement : <operation ..>
 => PortType ~ interface[JAVA]
 =>Operation ~ Method[JAVA]
 -<operation>  has : 
       1)id : name=".."
        2)Messages Exploited: 
                    if   <input > => message transmit to service .
                    if  <output > => message product by service .
                    if  <fault > => error message(~ exception ).
        - <input>,<output> &<fault> has : 
                     1. id : name=".."
                      2.message : reference to message . 
Example : (addPerson is an operation overloaded )
<portType name="Notebook">
<operation name="addPerson">
<input message="tns:addPersonWithComplexType" />
<output message="tns:addPersonWithComplexTypeResponse" />
</operation>
<operation name="addPerson" parameterOrder="name address birthyear">
<input message="tns:addPersonWithSimpleType" />
</operation>
<operation name="getPerson">
<input message="tns:getPerson" />
<output message="tns:getPersonResponse" />
</operation>
<operation name="getPersons">
<input message="tns:getPersons" />
<output message="tns:getPersonsResponse" />
</operation>
</portType>

Four models to define an operation:
1)One-way :
   * Client of service send message to operation &don't wait response
     *Use only one message <input>
    *Example : 
   <operation name="addPerson" parameterOrder="name address birthyear">
         <input message="tns:addPersonWithSimpleType"/>
    </operation>
2)Request/Response :
* Client of service send message to operation & Then  a message is returned to Client
     *One <input> , one <output> & one <fault>
    *Example : 
<operation name="addPerson" >
         <input message="tns:addPersonWithComplexType"/>
         <output message="tns:addPersonWithComplexTypeResponse"/>
    </operation>


3)Notification  :
 * Service send message to client 
     *Use only one message <output>
    *Example : 
 <operation name="personStatus">
         <output message="trackingInformation"/>
    </operation>


4)Solicit - response :
 * Client recieve message from service & response sent to service 
  *One <input> , one <output> & one <fault>
    *Example : 



<operation name="clientQuery" >
         <input message="bandWithRequest"/>
         <output message="bandwidthInfo"/>
         <fault message="faultMessage"/>
    </operation>


7.Binding Element 
 -it Perform Concret Part of portType .
  -Attibutes  => name=".."   portType="..."
  -it describes Protocol used to manage <portType> element :
                >>SOAP 1.* ,>>HTTP GET & Post  >>MIME
  -portType can be called more than once by several binding (each time use a different protocol )
General Structure  : 
<binding name="NamePortBinding" type="tns:portType">
 <!--Describes the protocol to use -->
  <operation name="operation1">
      <!--Action of the Protocol on the operation -->
    <input>
       <!-- Action on the protocol messages entered (input) -->
    </input>
    <output>
       <!-- Action of the Protocol on the output messages (ouput) -->
    </output>
    <fault>
        <!-- Action of the Protocol on the error messages (fault) -->
    </fault>
  </operation>
</binding> 
8. SOAP Binding
Name Space of SOAP : 
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
targetNamespace="http://schemas.xmlsoap.org/wsdl/soap/">

<xs:import namespace="http://schemas.xmlsoap.org/wsdl/" />

<xs:simpleType name="encodingStyle">
<xs:annotation>
<xs:documentation>
"encodingStyle" indicates any canonicalization conventions followed in the contents
of the containing element. For example, the value
"http://schemas.xmlsoap.org/soap/encoding/" indicates the pattern
described in SOAP specification
</xs:documentation>
</xs:annotation>
<xs:list itemType="xs:anyURI" />
</xs:simpleType>

<xs:element name="binding" type="soap:tBinding" />
<xs:complexType name="tBinding">
<xs:complexContent>
<xs:extension base="wsdl:tExtensibilityElement">
<xs:attribute name="transport" type="xs:anyURI" use="required" />
<xs:attribute name="style" type="soap:tStyleChoice"
use="optional" />
</xs:extension>
</xs:complexContent>
</xs:complexType>

<xs:simpleType name="tStyleChoice">
<xs:restriction base="xs:string">
<xs:enumeration value="rpc" />
<xs:enumeration value="document" />
</xs:restriction>
</xs:simpleType>

<xs:element name="operation" type="soap:tOperation" />
<xs:complexType name="tOperation">
<xs:complexContent>
<xs:extension base="wsdl:tExtensibilityElement">
<xs:attribute name="soapAction" type="xs:anyURI" use="optional" />
<xs:attribute name="style" type="soap:tStyleChoice"
use="optional" />
</xs:extension>
</xs:complexContent>
</xs:complexType>

<xs:element name="body" type="soap:tBody" />
<xs:attributeGroup name="tBodyAttributes">
<xs:attribute name="encodingStyle" type="soap:encodingStyle"
use="optional" />
<xs:attribute name="use" type="soap:useChoice" use="optional" />
<xs:attribute name="namespace" type="xs:anyURI" use="optional" />
</xs:attributeGroup>
<xs:complexType name="tBody">
<xs:complexContent>
<xs:extension base="wsdl:tExtensibilityElement">
<xs:attribute name="parts" type="xs:NMTOKENS" use="optional" />
<xs:attributeGroup ref="soap:tBodyAttributes" />
</xs:extension>
</xs:complexContent>
</xs:complexType>

<xs:simpleType name="useChoice">
<xs:restriction base="xs:string">
<xs:enumeration value="literal" />
<xs:enumeration value="encoded" />
</xs:restriction>
</xs:simpleType>

<xs:element name="fault" type="soap:tFault" />
<xs:complexType name="tFaultRes" abstract="true">
<xs:complexContent>
<xs:restriction base="soap:tBody">
<xs:attribute ref="wsdl:required" use="optional" />
<xs:attribute name="parts" type="xs:NMTOKENS" use="prohibited" />
<xs:attributeGroup ref="soap:tBodyAttributes" />
</xs:restriction>
</xs:complexContent>
</xs:complexType>
<xs:complexType name="tFault">
<xs:complexContent>
<xs:extension base="soap:tFaultRes">
<xs:attribute name="name" type="xs:NCName" use="required" />
</xs:extension>
</xs:complexContent>
</xs:complexType>


<xs:element name="header" type="soap:tHeader" />
<xs:attributeGroup name="tHeaderAttributes">
<xs:attribute name="message" type="xs:QName" use="required" />
<xs:attribute name="part" type="xs:NMTOKEN" use="required" />
<xs:attribute name="use" type="soap:useChoice" use="required" />
<xs:attribute name="encodingStyle" type="soap:encodingStyle"
use="optional" />
<xs:attribute name="namespace" type="xs:anyURI" use="optional" />
</xs:attributeGroup>
<xs:complexType name="tHeader">
<xs:complexContent>
<xs:extension base="wsdl:tExtensibilityElement">
<xs:sequence>
<xs:element ref="soap:headerfault" minOccurs="0"
maxOccurs="unbounded" />
</xs:sequence>
<xs:attributeGroup ref="soap:tHeaderAttributes" />
</xs:extension>
</xs:complexContent>
</xs:complexType>

<xs:element name="headerfault" type="soap:tHeaderFault" />
<xs:complexType name="tHeaderFault">
<xs:attributeGroup ref="soap:tHeaderAttributes" />
</xs:complexType>

<xs:element name="address" type="soap:tAddress" />
<xs:complexType name="tAddress">
<xs:complexContent>
<xs:extension base="wsdl:tExtensibilityElement">
<xs:attribute name="location" type="xs:anyURI" use="required" />
</xs:extension>
</xs:complexContent>
</xs:complexType>

</xs:schema>

 EXAMPLE (SOAP 1.1) : 


<!-- Définition de la partie Abstraite du WSDL -->                                                                                                                                                                                                                                                                       
<binding name="NoteBookPortBinding" type="tns:Notebook">
   <soap:binding transport="http://schemas.xmlsoap.org/soap/http"
style="rpc" />
   <operation name="addPersonWithComplexType">
     <soap:operation soapAction="" />
       <input>
         <soap:body use="literal" namespace="http://notebookwebservice.lisi.ensma.fr/" />
       </input>
       <output>
         <soap:body use="literal" namespace="http://notebookwebservice.lisi.ensma.fr/" />
       </output>
   </operation>
   <operation name="addPersonWithSimpleType">
     <soap:operation soapAction="" />
       <input>
         <soap:body use="literal" namespace="http://notebookwebservice.lisi.ensma.fr/" />
       </input>
   </operation>
   <operation name="getPerson">
    <soap:operation soapAction="" />
     <input>
       <soap:body use="literal" namespace="http://notebookwebservice.lisi.ensma.fr/" />
     </input>
     <output>
       <soap:body use="literal" namespace="http://notebookwebservice.lisi.ensma.fr/" />
     </output>
  </operation>
...
</binding>
</definitions>

1)<soap:binding> should be present when the definition of binding based on SOAP
2)style Attribute of <soap:binding>  indicate how SOAP messages created for the set of Operations.
   =>rpc (SOAP RPC)
   =>Document(XML)
3)transport Attribute of <soap:binding>  : Allows to specify the protocol used to transport Message.(As :HTTP,SMTP,FTP,...)
4) <soap:operation> should be present for each operation defined in the Abstract part of Document.
5)soap:Action attribute =>value of HTTP Header
6)<soap:body> specify the format of messages exchanged by operation.
7)use attribute characterizes the shape of parts of messages .
>>encoded: Transformation in the mechanism defined by the encodingStyle attribute.
>>literal: No transformation of message parts, they appear directly .


9.Service & Port Element
 *Element service  : define input points of WS. & by grouping <port> element .
   * <port> specify an address for a binding . 
    ==> 2attributes : name="..."  , binding="<nameOfBinding>"
   * If Type of binding is SOAP => <soap:address> specify URI of port.
   Example : 
<service name="Notebook">
     <port name="NoteBookPort" binding="tns:NoteBookPortBinding">
          <soap:address location="http://localhost:8080/NotebookWebService/notebook" />
     </port>
</service>

================================================================  

10.Binding HTTP GET & Post :
 Example :WSDL return  GIF or JPG
<definitions .>
<message name="m1">
<part name="part1" type="xsd:string" />
<part name="part2" type="xsd:int" />
<part name="part3" type="xsd:string" />
</message>
<message name="m2">
<part name="image" type="xsd:binary" />
</message>
<portType name="pt1">
<operation name="o1">
<input message="tns:m1" />
<output message="tns:m2" />
</operation>
</portType>
<service name="service1">
<port name="port1" binding="tns:b1">
<http:address location="http://example.com/" />
</port>
<port name="port2" binding="tns:b2">
<http:address location="http://example.com/" />
</port>
<port name="port3" binding="tns:b3">
<http:address location="http://example.com/" />
</port>
</service>
<binding name="b1" type="pt1">
<http:binding verb="GET" />
<operation name="o1">
<http:operation location="o1/A(part1)B(part2)/(part3)" />
<input>
<http:urlReplacement />
</input>
<output>
<mime:content type="image/gif" />
<mime:content type="image/jpeg" />
</output>
</operation>
</binding>
<binding name="b2" type="pt1">
<http:binding verb="GET" />
<operation name="o1">
<http:operation location="o1" />
<input>
<http:urlEncoded />
</input>
<output>
<mime:content type="image/gif" />
<mime:content type="image/jpeg" />
</output>
</operation>
</binding>
<binding name="b3" type="pt1">
<http:binding verb="POST" />
<operation name="o1">
<http:operation location="o1" />
<input>
<mime:content type="application/x-www-form-urlencoded" />
</input>
<output>
<mime:content type="image/gif" />
<mime:content type="image/jpeg" />
</output>
</operation>
</binding>
</definitions>



 .Reference : 

No comments:

Post a Comment