Webservices ... it doesn't work .... why
Posted: Thu Aug 20, 2009 11:19 am
Hi, everybody.
I have a little pb with my PHP webservices.
I don't know why but it doesn't work at all.
If i don't use a "SOAP model", it's OK (I mean, with classical functions) and my sql query is OK (I have data). but when i use SOAP ... no.
Why !! please help me.
here is an image of the disaster
I try to attach my files but ... PHP is not allowed so ...
------------------------------------------------------------------------------------------
File 1 : Index.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr" >
<head>
<title>Page d'information de la base </title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<style type="text/css">
</style>
</head>
<body>
<?php
require_once("lib/nusoap.php");
$wsdl = 'http://toto.free.fr/serveur_ws/produit_menu.wsdl';
$options = array(
'compression'=>true,
'exceptions'=>false,
'trace'=>true
);
$param = array(
'nom_menu' => 'menu grand mere,
'num_element' => 1,
);
$serv_customers = new SoapClient($wsdl, $options);
if( !$serv_customers )
die( "Creation client SOAP non realisée" );
/* It's like this function was never call !!! */
$TabProduit = $serv_customers->call('selection_produit',$param);
if( !$TabProduit )
die( "Call non realisée" ); /* I have this message in my page */
print_r($TabProduit);
print "\n\n";
/* erreur a l'execution : is_soap_fault n'est pas reconnu ??*/
if (is_soap_fault($TabProduit)) {
echo 'fault : ';
var_dump($serv_customers->__getLastRequest());
var_dump($serv_customers->__getLastRequestHeaders());
} else {
echo '<pre>'.var_export($TabProduit, true).'</pre>';
}
//print_r($TabProduit);
//print "\n\n";
//affichage des produits dans une liste de choix
echo "<form name='.....' method='post' action='index.php'>
<label width='250'>Type de produits disponibles : </label>
<select name='Tableau_produit'>";
//ajout dynamique d'items dans la liste//
for ($i=0; $i<sizeof($TabProduit); $i++){
echo $TabProduit[$i];
echo "<option value='".$TabProduit[$i]."'> ".$TabProduit[$i]." </option>";
}
echo "</select>";
echo "</form>";
?>
</body>
</html>
---------------------------------------------------------------------------------------------------
File 2 : produit_menu.php
<?php
require_once ("../lib/nusoap.php");
class produit_menu{
function selection_produit($nom_menu, $num_element)
{
$query = "SELECT distinct libelle_produit from menu, menu_produit, categorie WHERE menu.id_menu=menu_produit.id_menu AND num_element = $num_element AND type_menu = '".$nom_menu."'";
// On se connecte a la base
$link = mysql_connect('http://toto.free.fr/', toto, 'toto');
if( !$link )
die( "Connexion BD impossible" );
// On selectionne la base
$result = mysql_select_db('toto');
if( !$result )
die( "Echec de la selection de la base" );
// On récupère les infos de la BD
$retour = @mysql_query($query, $link);
if( !$retour )
die( "Echec de la requete SQL" );
//on empile les resultats dans un tableau TabCarb
$Tabproduit=array();
while ($ligne = mysql_fetch_array ($retour)){
$Tabproduit[]=$ligne['libelle_produit']; // avec fetch_array on accede directement au nom de champ }
return $Tabproduit;//on retourne le tableau
}
}
$wsdl = 'produit_menu.wsdl';
$serveur = new soap_server($wsdl);
$server->setClass('produit_menu');
$server->handle();
$HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : »;
$server->service($HTTP_RAW_POST_DATA); // Executes the RPC
?>
------------------------------------------------------------------------------------------------
File 3 : produit_menu.wsdl
<?xml version='1.0' encoding='UTF-8'?>
<definitions name="produit_menu" targetNamespace="urn:produit_menu"
xmlns:typens="urn:produit_menu"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns="http://schemas.xmlsoap.org/wsdl/">
<types>
<schema xmlns="http://www.w3.org/2000/10/XMLSchema">
<complexType name="ArrayOfproduit_menu">
<complexContent>
<restriction base="soapenc:Array"/>
</complexContent>
</complexType>
</schema>
</types>
<message name="selection_produit">
<part name="nom_menu" type="xsd:string"/>
<part name="num_element" type="xsd:integer"/>
</message>
<message name="selection_produitResponse">
<part name="selection_produitReturn" type="ArrayOfproduit_menu"/>
</message>
<portType name="produit_menuPortType">
<operation name="selection_produit">
<input message="typens:selection_produit"/>
<output message="typens:selection_produitResponse"/>
</operation>
</portType>
<binding name="produit_menuBinding" type="typens:produit_menuPortType">
<soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
<operation name="selection_produit">
<soap:operation soapAction="urn:produit_menuAction"/>
<input>
<soap:body namespace="urn:produit_menu" use="encoded"
encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</input>
<output>
<soap:body namespace="urn:produit_menu" use="encoded"
encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</output>
</operation>
</binding>
<service name="produit_menuService">
<port name="produit_menuPort" binding="typens:produit_menuBinding">
<soap:address location="http://toto.free.fr/serveur_ws/produit_menu.php"/>
</port>
</service>
</definitions>
I have a little pb with my PHP webservices.
I don't know why but it doesn't work at all.
If i don't use a "SOAP model", it's OK (I mean, with classical functions) and my sql query is OK (I have data). but when i use SOAP ... no.
Why !! please help me.
here is an image of the disaster
I try to attach my files but ... PHP is not allowed so ...
------------------------------------------------------------------------------------------
File 1 : Index.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr" >
<head>
<title>Page d'information de la base </title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<style type="text/css">
</style>
</head>
<body>
<?php
require_once("lib/nusoap.php");
$wsdl = 'http://toto.free.fr/serveur_ws/produit_menu.wsdl';
$options = array(
'compression'=>true,
'exceptions'=>false,
'trace'=>true
);
$param = array(
'nom_menu' => 'menu grand mere,
'num_element' => 1,
);
$serv_customers = new SoapClient($wsdl, $options);
if( !$serv_customers )
die( "Creation client SOAP non realisée" );
/* It's like this function was never call !!! */
$TabProduit = $serv_customers->call('selection_produit',$param);
if( !$TabProduit )
die( "Call non realisée" ); /* I have this message in my page */
print_r($TabProduit);
print "\n\n";
/* erreur a l'execution : is_soap_fault n'est pas reconnu ??*/
if (is_soap_fault($TabProduit)) {
echo 'fault : ';
var_dump($serv_customers->__getLastRequest());
var_dump($serv_customers->__getLastRequestHeaders());
} else {
echo '<pre>'.var_export($TabProduit, true).'</pre>';
}
//print_r($TabProduit);
//print "\n\n";
//affichage des produits dans une liste de choix
echo "<form name='.....' method='post' action='index.php'>
<label width='250'>Type de produits disponibles : </label>
<select name='Tableau_produit'>";
//ajout dynamique d'items dans la liste//
for ($i=0; $i<sizeof($TabProduit); $i++){
echo $TabProduit[$i];
echo "<option value='".$TabProduit[$i]."'> ".$TabProduit[$i]." </option>";
}
echo "</select>";
echo "</form>";
?>
</body>
</html>
---------------------------------------------------------------------------------------------------
File 2 : produit_menu.php
<?php
require_once ("../lib/nusoap.php");
class produit_menu{
function selection_produit($nom_menu, $num_element)
{
$query = "SELECT distinct libelle_produit from menu, menu_produit, categorie WHERE menu.id_menu=menu_produit.id_menu AND num_element = $num_element AND type_menu = '".$nom_menu."'";
// On se connecte a la base
$link = mysql_connect('http://toto.free.fr/', toto, 'toto');
if( !$link )
die( "Connexion BD impossible" );
// On selectionne la base
$result = mysql_select_db('toto');
if( !$result )
die( "Echec de la selection de la base" );
// On récupère les infos de la BD
$retour = @mysql_query($query, $link);
if( !$retour )
die( "Echec de la requete SQL" );
//on empile les resultats dans un tableau TabCarb
$Tabproduit=array();
while ($ligne = mysql_fetch_array ($retour)){
$Tabproduit[]=$ligne['libelle_produit']; // avec fetch_array on accede directement au nom de champ }
return $Tabproduit;//on retourne le tableau
}
}
$wsdl = 'produit_menu.wsdl';
$serveur = new soap_server($wsdl);
$server->setClass('produit_menu');
$server->handle();
$HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : »;
$server->service($HTTP_RAW_POST_DATA); // Executes the RPC
?>
------------------------------------------------------------------------------------------------
File 3 : produit_menu.wsdl
<?xml version='1.0' encoding='UTF-8'?>
<definitions name="produit_menu" targetNamespace="urn:produit_menu"
xmlns:typens="urn:produit_menu"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns="http://schemas.xmlsoap.org/wsdl/">
<types>
<schema xmlns="http://www.w3.org/2000/10/XMLSchema">
<complexType name="ArrayOfproduit_menu">
<complexContent>
<restriction base="soapenc:Array"/>
</complexContent>
</complexType>
</schema>
</types>
<message name="selection_produit">
<part name="nom_menu" type="xsd:string"/>
<part name="num_element" type="xsd:integer"/>
</message>
<message name="selection_produitResponse">
<part name="selection_produitReturn" type="ArrayOfproduit_menu"/>
</message>
<portType name="produit_menuPortType">
<operation name="selection_produit">
<input message="typens:selection_produit"/>
<output message="typens:selection_produitResponse"/>
</operation>
</portType>
<binding name="produit_menuBinding" type="typens:produit_menuPortType">
<soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
<operation name="selection_produit">
<soap:operation soapAction="urn:produit_menuAction"/>
<input>
<soap:body namespace="urn:produit_menu" use="encoded"
encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</input>
<output>
<soap:body namespace="urn:produit_menu" use="encoded"
encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</output>
</operation>
</binding>
<service name="produit_menuService">
<port name="produit_menuPort" binding="typens:produit_menuBinding">
<soap:address location="http://toto.free.fr/serveur_ws/produit_menu.php"/>
</port>
</service>
</definitions>