[英]Create complex type nusoap php
我從事個人Web服務nusoap的項目,上周我第一次通過Web信息啟動Web服務。
目前,我正在嘗試編寫一個以表格形式插入元素的網絡服務。
這是文件服務器:
require_once ('lib/nusoap.php');
$server = new nusoap_server();
$server->configureWSDL("test", "urn:Test/", "http://localhost/testajout/server.php");
$server->wsdl->schemaTargetNamespace="http://localhost/testajout/server.php";
$server->soap_defencoding = 'utf-8';
//register of method
$server->wsdl->addComplexType(
'cordonne',
'complexType',
'struct',
'all',
'',
array(
'ID'=> array('name' => 'id', 'type' => 'xsd:int'),
'prenom'=> array('name' => 'prenom', 'type' => 'xsd:string'),
'lastname'=> array('name' => 'lastname', 'type' => 'xsd:string'),
'datedebut'=> array('name' => 'datedebut', 'type' => 'xsd:date'),
'solde'=> array('name' => 'solde', 'type' => 'xsd:decimal'),
'identifient'=> array('name' => 'identifient', 'type' => 'xsd:string'),
'photo' => array('name' => 'photo', 'type' => 'xsd:string'),
'fid'=> array('name' => 'fid', 'type' => 'xsd:int'),
'codebarre' => array('name' => 'codebarre', 'type' => 'xsd:string')
));
$server->register('InsertUser',array('cordonne'=>'tns:cordonne'),array('return' =>'xsd:string'));
function InsertUser($cordonne){
$cordonne=array();
$db1=new PDO('mysql:host=localhost;dbname=service','root','');
/* $req1 = $db1->prepare("SELECT * FROM myusers WHERE identifient =:identifient");
$req1->execute(array(':identifient' =>$identifient));
$count = $req1->rowCount();
if($count){
return "existe déja";
}else{*/
$id=$cordonne['id'];
$prenom = $cordonne['nom'];
$lastname = $cordonne['prenom'];
$datedebut = $cordonne['datedebut'];
$solde = $cordonne['solde'];
$login = $cordonne['identifient'];
$photo =$cordonne['photo'];
$fid=$cordonne['fid'];
$codebarre=$cordonne['codebarre'];
$req=$db1->prepare("insert into myusers values(:ID,:Prenom,:LastName,:dateDebut,:solde,:identifient,:photo,:fidelit,:CodeBarre)");
$req->execute(array(':ID'=>$id,':Prenom'=>$prenom,':LastName'=>$lastname,':dateDebut'=>date("Y-m-d", strtotime( $datedebut)),':solde'=>$solde,
':identifient'=>$login,':photo'=>$photo,':fidélit'=>$fid,':CodeBarre'=>$codebarre));
return "client ajouter";
}
客戶代碼:
error_reporting(E_ALL);
// Pull in the NuSOAP code
require_once('lib/nusoap.php');
// Create the client instance
$client = new nusoap_client('http://localhost/testajout/server.php');
$cordonne['id']=NULL;
$cordonne['nom']=$_POST['nom'];
$cordonne['prenom']=$_POST['prenom'];
$cordonne['datedebut']=$_POST['dateDebut'];
$cordonne['solde']=$_POST['solde'];
$cordonne['identifient']=$_POST['identifient'];
$cordonne['photo']=$_POST['photo'];
$cordonne['fid']=$_POST['clientFid'];
$cordonne['codebarre']=$_POST['codebarre'];
$res = $client->call('InsertUser',array('cordonne'=>$cordonne));
print_r($res);
什么都沒顯示。
請在復雜類型數組的定義中使用正確的數組鍵
$server->wsdl->addComplexType(
'cordonne',
'complexType',
'struct',
'all',
'',
array(
'id'=> array('name' => 'id', 'type' => 'xsd:int'),
'prenom'=> array('name' => 'prenom', 'type' => 'xsd:string'),
'lastname'=> array('name' => 'lastname', 'type' => 'xsd:string'),
'datedebut'=> array('name' => 'datedebut', 'type' => 'xsd:date'),
'solde'=> array('name' => 'solde', 'type' => 'xsd:decimal'),
'identifient'=> array('name' => 'identifient', 'type' => 'xsd:string'),
'photo' => array('name' => 'photo', 'type' => 'xsd:string'),
'fid'=> array('name' => 'fid', 'type' => 'xsd:int'),
'codebarre' => array('name' => 'codebarre', 'type' => 'xsd:string')
));
而不是將帶有密鑰的數組傳遞給服務器,而只是發送沒有密鑰的數組
$res = $client->call('InsertUser',array($cordonne));
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.