创建复杂类型的nusoap-php


Create complex type nusoap php

我在做一个个人网络服务nusoap的项目,上周我第一次通过网络信息启动了该网络服务。

目前,我正在尝试编写一个以表的形式插入元素的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));