WELCOME Abdennour : Software engineer

May 15, 2012

3.SOAP => Communicate & Use SoapUI


This tutorial of course is an introduction to SOAP communication protocol used to communicate with a Web Service extended. The Tutorial begins with apresentation of the structure of a SOAP message. It is followed by a description of the header and body of a SOAP message. 


1.SOAP Generalities 
2.HelloWorld Service (SOA for Example) 
3. Structure of SOAP Message: 
4.SOAP Header  :
5. SOAP Body:
6.SOAP &HTTP transport



1.SOAP Generalities : 
-SOAP : Simple Object Access Protocol . 
-SOAP : Protocol of communication between applications based on XML langage .
-Inventor of SOAP : Microsoft & IBM .
   Comparaison :



   Where's Soap Used :

1.SOAP Generalities : 
-SOAP : Simple Object Access Protocol . 
-SOAP : Protocol of communication between applications based on XML langage .


-A SOAP message can be transmitted to several receivers intermediary before being received by the receiver end (~ chain of responsibility)
 -A SOAP message is transported to the receiver using a transport protocol (HTTP, SMTP, ...)
2.HelloWorld Service (SOA for Example) 

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:hel="http://helloworldwebservice.lisi.ensma.fr/">
<soapenv:Header />
<soapenv:Body>
<hel:makeHelloWorld>
<value>Abdennour Toumi</value>
</hel:makeHelloWorld>
</soapenv:Body>
</soapenv:Envelope>
SOAP message to invoke the operation makeHelloWorld containing a value parameter
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:hel="http://helloworldwebservice.lisi.ensma.fr/">
<soapenv:Header />
<soapenv:Body>
<hel:simpleHelloWorld />
</soapenv:Body>
</soapenv:Envelope>
SOAP message to invoke the 
operation simpleHelloWorld not containing parameter

Responses By SOAP Messages Also : 

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<ns2:makeHelloWorldResponse
xmlns:ns2="http://helloworldwebservice.lisi.ensma.fr/">
<helloWorldResult>Hello World to Abdennour Toumi</helloWorldResult>
</ns2:makeHelloWorldResponse>
</soapenv:Body>
</soapenv:Envelope>

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<ns2:simpleHelloWorldResponse
xmlns:ns2="http://helloworldwebservice.lisi.ensma.fr/">
<helloWorldResult>Hello World to everybody</helloWorldResult>
</ns2:simpleHelloWorldResponse>
</soapenv:Body>
</soapenv:Envelope>


3. Structure of SOAP Message: 
-2Parts : 
        1) Header(can be optional) 
        2) Body  . 

-Soap Message is an envelop . 
-<soapenv:Enveloppe> is the root of SOAP Message . 
- the tag(Balises) and subtags must be explicitly associated to a namespace.

-SOAP Specification define 2 nameSpaces : 
 =>SOAP-ENVor soapenv: http://schemas.xmlsoap.org/soap/envelope/
=>SOAP-ENC:http://schemas.xmlsoap.org/soap/encoding/
-Request & Response have the Same Message Structure. 
4.SOAP Header  :
-SOAP Message Header is used to transmit additional information about this message.
SOAP : Simple Object Access Protocol . 
-it's defined by : <SOAP-ENV:Header>
-Utility : TRansmit =>Authentification Info , Transaction Context ...
5. SOAP Body:
-it's defined by : <SOAP-ENV:Body>
-  <SOAP-ENV:Body>can contain either: 
   >>>An error in response to a query (<SOAP-ENV:Fault> element) 
   >>>or information sent to the recipient of the SOAP message which respect an encoding.
-Encoding of inofrmations is specified by WSDL Doxument : 
   >>>Style Attribute(Doc|RPC)
  >>>use Attribute(encoded|litteral)
Conventions of Request Message : 
1.name of struct is the name of operation .
2.Each Param of Operation is defined as sebElement of Struct Element .
Conventions of Response Message : 
1.name of struct is the name of operation followed by Response
2.Each Param of Operation is defined as sebElement of Struct Element .

Example : 
<!-- Request -->
<!-- Call addPersonWithComplexType -->
<!-- Parameter a complex type is defined in a structure (newPerson) -->
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:not="http://notebookwebservice.lisi.ensma.fr/">
<soapenv:Header />
<soapenv:Body>
<not:addPersonWithComplexType>
<newPerson>
<address>Insat TN</address>
<birthyear>23121989</birthyear>
<name>Abdennour Toumi</name>
</newPerson>
</not:addPersonWithComplexType>
</soapenv:Body>
</soapenv:Envelope>



<!-- Call addPersonWithSimpleType -->
<!-- 3 Param without complex type -->
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:not="http://notebookwebservice.lisi.ensma.fr/">
<soapenv:Header />
<soapenv:Body>
<not:addPersonWithSimpleType>
<name>Abdennour Toumi</name>
<address>Insat TN</address>
<birthyear>23121989</birthyear>
</not:addPersonWithSimpleType>
</soapenv:Body>
</soapenv:Envelope>


<!-- Response -->
<!-- THe Name OF operations is followed by Response -->
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<ns2:addPersonWithComplexTypeResponse
xmlns:ns2="http://notebookwebservice.lisi.ensma.fr/">
<addPersonWithComplexTypeResult>true
</addPersonWithComplexTypeResult>
</ns2:addPersonWithComplexTypeResponse>
</soapenv:Body>
</soapenv:Envelope>


<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<ns2:addPersonWithSimpleTypeResponse
xmlns:ns2="http://notebookwebservice.lisi.ensma.fr/">
<addPersonWithSimpleTypeResult>true</addPersonWithSimpleTypeResult>
</ns2:addPersonWithSimpleTypeResponse>
</soapenv:Body>
</soapenv:Envelope>

6.SOAP &HTTP transport
 -Protocols used by SOAP to transport messages SOAP from sender to reciever :
 ==>>HTTP, SMTP, FTP, POP3 et NNTP.
-The request / response SOAP model is perfectly suited to model HTTP request / response .

 A.Request SOAP HTTP : 
-Method (POST) need attribut SOAPAction.

POST http://localhost:8080/NotebookWebService/notebook HTTP/1.1

Content-Type: text/xml;charset=UTF-8
SOAPAction: ""
User-Agent: Jakarta Commons-HttpClient/3.1
Host: localhost:8080
Content-Length: 459

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"

xmlns:not="http://notebookwebservice.lisi.ensma.fr/">
  <soapenv:Header />
  <soapenv:Body>
    <not:addPersonWithComplexType>
      <newPerson>
        <address>Insat TN</address>
        <birthyear>23121989</birthyear>
        <name>Abdennour Toumi</name>
     </newPerson>
    </not:addPersonWithComplexType>
  </soapenv:Body>
</soapenv:Envelope>

B . Response SOAP HTTP : 
-if HTTP Header Code=2** ==> Message SOAP is recieved 
-if HTTP Header Code=500 ==> Error => SOAP Body Should Have <..fault..>
=========================================== =  = = =
 HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
Content-Type: text/xml;charset=utf-8
Transfer-Encoding: chunked
Date: Sun, 13 Dec 2009 12:00:33 GMT
<?xml version='1.0' encoding='UTF-8'?>
<soapenv:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
  <soapenv:Body>
    <ns2:addPersonWithComplexTypeResponse
xmlns:ns2="http://notebookwebservice.lisi.ensma.fr/">
      <addPersonWithComplexTypeResult>
             true
      </addPersonWithComplexTypeResult>
    </ns2:addPersonWithComplexTypeResponse>
  </soapenv:Body>
</soapenv:Envelope>

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

 .Reference : 

1 comment: