Web service

verbeyst Messages postés 77 Date d'inscription mardi 10 mars 2009 Statut Membre Dernière intervention 15 février 2011 - 24 févr. 2009 à 17:12
thedarkkillerz Messages postés 18 Date d'inscription samedi 3 juillet 2004 Statut Membre Dernière intervention 21 juin 2010 - 21 juin 2010 à 11:56
J'ai une question concernant les web services en php.
Le bout de code ci-après fonctionne bien quand je fait un appel client, il s'agit d'une version sans configuration du WSDL.
Par contre lorsque j'essaie de configurer le WSDL, je n'ai plus rien.
Ma méthode getListOfPatients(...)  exposée par mon web service ne me retourne  que "Array".

VERSION sans WSDL
------------------------
<?php

//importation de la librairie nuSOAP

require_once('nusoap/lib/nusoap.php');

// On crée un objet soap server

$server = new soap_server;

$server->register('getListofPatientsGP');

// Implémentation de la méthode web

// Cette méthode retourne la liste des Code Patient liés au médecin traitant dont le codeInami est

// passé en paramètre

function getListofPatientsGP($codeInami)

{

include ("connexion.php");

$codeInami=substr($codeInami,0,6); // abcd

if ($conn==false)

{return new soap_fault("Server", "Oracle", "echec connexion");

}

$query = 'BEGIN PKG_MED_EXT.PRC_GetListOfPatientsGP(:codeInami, :message); END;';

//préparer la requête sql avec oracle et retourner l'identifiant de la requête

$stmt = oci_parse($conn,$query);

//Si problème retourner un msg erreur

if (!$stmt)

{

//return 'stmt bad';

throw new soap_fault(-1,"failed to prepare query(reason :".oci_error(!$stmt).")");

}

//Associer une variable PHP à une variable SQL Oracle

oci_bind_by_name($stmt,":codeInami",$codeInami,6);

//oci_bind_by_name($stmt,":message",$message,32);

// Create a new cursor resource

$message = oci_new_cursor($conn);

// Bind the cursor resource to the Oracle argument

oci_bind_by_name($stmt,":message",$message,-1,OCI_B_CURSOR);

// exécution de la requête sql si problème msg erreur

if (!oci_execute($stmt))

{

//return 'oci_execute bad';

throw new soap_fault(-1,"failed to execute query (reason:".oci_error($stmt).")");

}

// Execute the cursor

oci_execute($message);

//return "a exécuté oci_execute_message";

oci_fetch_all($message, $cursor, null, null, OCI_FETCHSTATEMENT_BY_ROW);

return $cursor;

//include("Deconnexion.php");

}

//isset renvoie true si la variable est définie sinon renvoie false

$HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : '';

$server->service($HTTP_RAW_POST_DATA);

?>

VERSION avec configuration du WSDL
*******************************

<?php

//importation de la librairie nuSOAP

require_once('nusoap/lib/nusoap.php');

// On crée un objet soap server

$server = new soap_server;

//configuration de notre serveur SOAP

$server->configureWSDL('DBMGPWebService', 'DBMGPWebService');

$server->register(

'getListofPatientsGP', // method name

array('codeInami' => 'xsd:string'), // input parameters

array('return' => 'xsd:string'), // output parameters

'urn:DBMGPWebService', // namespace

'urn:DBMGPWebService#getListofPatientsGP', // SOAPAction

'rpc', // style

'encoded'

); // use*/

// Implémentation de la méthode web

// Cette méthode retourne la liste des Code Patient liés au médecin traitant dont le codeInami est

// passé en paramètre

function getListofPatientsGP($codeInami)

{ //return $codeInami;

include ("connexion.php");

// $codeInami=substr($codeInami,0,6);

if ($conn==false)

{throw new soap_fault("Server", "Oracle", "echec connexion");

}

//Procédure stockée

$query = 'BEGIN PKG_MED_EXT.PRC_GetListOfPatientsGP(:codeInami, :message); END;';

//préparer la requête stockée avec oracle et retourner l'identifiant de la requête

$stmt = oci_parse($conn,$query);

//Si problème retourner un msg erreur

if (!$stmt)

{

throw new soap_fault(-1,"failed to prepare query(reason :".oci_error(!$stmt).")");

}

//Associer une variable PHP à une variable SQL Oracle

oci_bind_by_name($stmt,":codeInami",$codeInami,6);

// Créer a new cursor resource

$message = oci_new_cursor($conn);

// Associer la variable curseur $message à l'argumentt correspondnat oracle

oci_bind_by_name($stmt,":message",$message,-1,OCI_B_CURSOR);

// exécution de la requête (de la procédure stockée) si problème msg erreur

if (!oci_execute($stmt))

{

throw new soap_fault(-1,"failed to execute query (reason:".oci_error($stmt).")");

}

// Exécuter le curseur

oci_execute($message);

$cursor = array();

oci_fetch_all($message, $cursor, null, null, OCI_FETCHSTATEMENT_BY_ROW);

include("Deconnexion.php");

return $cursor;

//return new soapval('return', 'xsd:array()',$cursor);

}

//isset renvoie true si la variable est définie sinon renvoie false

$HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : '';

$server->service($HTTP_RAW_POST_DATA);

?>

verbeyst

1 réponse

thedarkkillerz Messages postés 18 Date d'inscription samedi 3 juillet 2004 Statut Membre Dernière intervention 21 juin 2010
21 juin 2010 à 11:56
Bonjour,
j'ai eu le même problème, j'ai trouvé la solution içi:
http://www.nonplus.net/geek/000752.php

Dans cet exemple, la fonction exposée a le type de retour "ChapterArray"

Ligne de config NuSoap:
array('return' => 'tns:ChapterArray'),


Exemple:
//Déclaration du type complexe
$server->wsdl->addComplexType(
'Chapter',
'complexType',
'struct',
'all',
'',
array(
'title' => array('name'=>'title','type'=>'xsd:string'),
'page' => array('name'=>'page','type'=>'xsd:int')
)
);

//Déclaration du type complexe en version Array
$server->wsdl->addComplexType(
'ChapterArray',
'complexType',
'array',
'',
'SOAP-ENC:Array',
array(),
array(
array('ref'=>'SOAP-ENC:arrayType','wsdl:arrayType'=>'tns:Chapter[]')
),
'tns:Chapter'
);


J'espère que ça t'aidera..
0
Rejoignez-nous