[英]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.