PHP,带有nusoap的MYSQL Web服务

时间:2013-07-16 14:02:16

标签: php mysql web-services soap

我开始学习Web服务,我正在做一些测试。

我正在尝试编写一个服务来将表的所有数据传递到我的客户端,但我无法使其工作。

第一个'servei'有效,但第二个没有。

任何建议将不胜感激。感谢

service.php     

require 'lib/nusoap.php';    

$server = new nusoap_server();
$server->configureWSDL("test" . "urn:test");    

include 'functions.php';    

$server->wsdl->addComplexType('servei', 'complexType', 'struct', 'all', '', array(
    'preu_antic' => array('name' => 'preu_antic', 'type' => 'xsd:float'),
    'preu_actual' => array('name' => 'preu_actual', 'type' => 'xsd:float'),
    'descompte_servei' => array('name' => 'descompte_servei', 'type' => 'xsd:float'),
));    

$server->wsdl->addComplexType('ServiceTypes', 'complexType', 'struct', 'all', '', array(
    'id_tipus_servei' => array('name' => 'id_tipus_servei', 'type' => 'xsd:inter'),
    'nom_tipus_servei' => array('name' => 'nom_tipus_servei', 'type' => 'xsd:string'),
    'descripcio_tipus_servei' => array('name' => 'descripcio_tipus_servei', 'type' => 'xsd:string'),
));    

$server->wsdl->addComplexType('ArrayOfServiceTypes', 'complexType', 'array', '', 'SOAP-ENC:Array', array(), array(
    array('ref' => 'SOAP-ENC:arrayType', 'wsdl:arrayType' => 'tns:ServiceTypes[]')), 'tns:ServiceTypes');    

$server->register('servei', array("id_servei" => 'xsd:inter'), array("return" => 'tns:servei'));
$server->register('getServiceTypes', array("idioma" => 'xsd:string'), array("return" => 'tns:ArrayOfServiceTypes'));    


$HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : '';
$server->service($HTTP_RAW_POST_DATA);
?>

的functions.php

function servei($id){
    conexio();
    $query_servei = mysql_query("SELECT * FROM servei WHERE id_servei = '$id'")or die(mysql_error());
    $row = mysql_fetch_array($query_servei);
    $preu_antic = $row['preu_antic'];
    $preu_actual = $row['preu_actual'];
    $descompte_servei = $row['descompte_servei'];

    $servei = array('preu_antic'=>$preu_antic,'preu_actual'=>$preu_actual,'descompte_servei'=>$descompte_servei);

    return $servei;
}    

function getServiceTypes($idioma){
    conexio();
    $query = mysql_query("SELECT id_tipus_servei, nom_tipus_servei, descripcio_tipus_servei FROM idioma_tipus_servei WHERE id_idioma = '$idioma'") or die(mysql_error());
    $n = 0;
    while ($row = mysql_fetch_array($query)) {
        $result[$n]['id_tipus_servei'] = $row['id_tipus_servei'];
        $result[$n]['nom_tipus_servei'] = $row['nom_tipus_servei'];
        $result[$n]['descripcio_tipus_servei'] = $row['descripcio_tipus_servei'];
        $n++;
    }
    return $result;
} 
?>

client.php

<?php
    require 'lib/nusoap.php';
    include 'functions.php';
    $client = new nusoap_client("http://192.168.8.155:8090/webservice/service.php?wsdl");    

   //$id=1;
   // $servei = $client -> call('servei',array("id_servei"=>"$id"));
   // print_r($servei);    


    $idioma ='ca';
    $servicetypes = $client -> call('getServiceTypes',array("idioma"=>"$idioma"));
    print_r($servicetypes);    

    ?>

2 个答案:

答案 0 :(得分:0)

好的,我处理过了。

如果您使用的是PHP 5.4,则必须在nusoap.php中对第6132行进行注释。

答案 1 :(得分:0)

如果我们要改变它,则无法解决这个问题:

$this->debug("serializing array element: $k, $v of type: $typeDef[arrayType]");

要:

$this->debug("serializing array element: $k, $v of type: " . $typeDef['arrayType'] );