Exercice 1

  • monFormat3.wsdl
<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://www.example.org/monFormat3/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="monFormat3" targetNamespace="http://www.example.org/monFormat3/">
<wsdl:types>
<xsd:schema targetNamespace="http://www.example.org/monFormat3/">
<xsd:element name="NewOperation">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="in" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="NewOperationResponse">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="out" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
</wsdl:types>
<wsdl:message name="QuelJourRequest">
<wsdl:part name="parameters" type="xsd:string"/>
</wsdl:message>
<wsdl:message name="QuelJourResponse">
<wsdl:part name="parameters" type="xsd:string"/>
</wsdl:message>
<wsdl:portType name="monFormat3">
<wsdl:operation name="QuelJour">
<wsdl:input message="tns:QuelJourRequest"/>
<wsdl:output message="tns:QuelJourResponse"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="monFormat3SOAP" type="tns:monFormat3">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="QuelJour">
<soap:operation soapAction="http://www.example.org/monFormat3/NewOperation"/>
<wsdl:input>
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="monFormat3">
<wsdl:port binding="tns:monFormat3SOAP" name="monFormat3SOAP">
<soap:address location="http://127.0.0.1/ws/tp1/ex1/serveur.php"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
<?php
// Pour supprimer le cache du web-service
ini_set('soap.wsdl_cache_enabled', 0);
// Pour définir le temp maximal d'éxecution de notre web-service
ini_set('default_socket_timeout', 180);
 
// Nom de notre web-service
class Server {
     // Le service QuelJour que l'on a définit dans notre format wsdl
    function QuelJour($parm) {
    	$aJour[1] = 'Lundi';
		$aJour[2] = 'Mardi';
		$aJour[3] = 'Mercredi';
		$aJour[4] = 'Jeudi';
		$aJour[5] = 'Vendredi';
		$aJour[6] = 'Samedi';
		$aJour[0] = 'Dimanche';
		return $aJour[date("w",strtotime($parm))];
    }
}
 
// On tente d'instancier la classe soapServer
// Si cela s'avère impossible, on affiche une erreur
try {
    $server = new SoapServer('monFormat3.wsdl',  array('trace' => 1,'encoding'	=> 'ISO-8859-1'));
    // On définit la classe qui va gérer les requêtes SOAP (pour nous c'est la class Server)
    $server->setclass('Server');
    $server->setPersistence(SOAP_PERSISTENCE_REQUEST);
} catch (Exception $e) {
    echo 'erreur'.$e;
}
// Si l'appel provient d'un Web-Service
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
	try {
		$server -> handle();}
	catch (Exception $e) {
    	echo 'erreur'.$e;
	}
}
// Facultatif seulement pour montrer les fonctions disponibles par le web-service
else {
    echo '<strong>This SOAP server can handle following functions : </strong>';
    echo '<ul>';
    foreach($server -> getFunctions() as $func) {
        echo '<li>' , $func , '</li>';
    }
    echo '</ul>';
}
 
 
?>
<?php
// Pour supprimer le cache du web-service
ini_set('soap.wsdl_cache_enabled', 0);
 
// Nouveau Client SOAP
try {
    // Nouvelle instance de la classe soapClient
   $client = new SoapClient('http://localhost/ws/tp1/ex1/monFormat3.wsdl', array('trace' => 1));
 
   $parm = '18-11-2011';
    // Appel de la méthode QuelJour du service web
 
   try{
    $oReturn =  $client -> QuelJour($parm);
	} catch (Exception $e) {
    	echo 'erreur1'.$e;
	} 
	catch (SoapFault $fault) {
		echo "il y a une erreur";
    	trigger_error("SOAP Fault: (faultcode: {$fault->faultcode}, faultstring: {$fault->faultstring})", E_USER_ERROR);
	}
        // affiche le résultat
	var_dump($oReturn);
} catch (SoapFault $fault) {
    echo 'erreur : '.$fault;
}
 
// Affichage des requêtes et réponses SOAP (pour debug)
 
	echo '<br />Requete SOAP : '.htmlspecialchars($client->__getLastRequest()).'<br />';
 
	echo '<br />Reponse SOAP : '.htmlspecialchars($client->__getLastResponse()).'<br />';
 
 
 
?>
require 'soap/wsdlDriver'
 
#create driver
 
wsdl = "http://127.0.0.1/ws/tp1/ex1/monFormat.wsdl"
 
driver = SOAP::WSDLDriverFactory.new(wsdl).create_rpc_driver
 
query = ""
 
@results = driver.QuelJour("")
 
puts @results