1

配列の配列を返すのに問題があります。nusoap を使用して php で Web サービスを作成しています。コードは次のとおりです。

サーバー.php

    <?php
    //libreria de nusoap
    require_once ('nusoap/lib/nusoap.php');

    $miURL = 'http://localhost/webservice/';
    $server = new soap_server();
    $server->configureWSDL('Web Service de Pruebas', $miURL);
    $server->wsdl->schemaTargetNamespace = $miURL;

    $server->wsdl->addComplexType(
            'array_php',
            'complexType',
            'struct',
            'all',
            '',
                array(
                    'pk' => array('name' => 'pk', 'type' =>'xsd:int'),
                    'rol' => array('name' => 'rol', 'type' =>'xsd:string'),
                    'descripcion' => array('name' => 'descripcion', 'type' =>'xsd:string')
                )
            );

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

    $server->register('prueba',                    // method name
        array(),                            // input parameters
        array('return' => 'tns:array_array'),    // output parameters
        $miURL,                         // namespace
        $miURL . '#prueba',                   // soapaction
        'rpc',                                    // style
        'encoded',                                // use
        'Get Specific array_php'        // documentation
      );

    function prueba()
    {
        $con = mysql_connect('localhost', 'root', '1234');
        mysql_selectdb('laboral', $con);

        $sql = "SELECT * FROM roles";
        $q = mysql_query($sql);

        $item = array();
        while($r = mysql_fetch_assoc($q)){
            $item[] = $r;
        }
        return $item;

    }


    if( !isset($HTTP_RAW_POST_DATA) )
        $HTTP_RAW_POST_DATA = file_get_contents( 'php://input' );

    $server->service($HTTP_RAW_POST_DATA);
?>

client.php

<?php
    //libreria nusoap
    require_once ('nusoap/lib/nusoap.php');

    //lineas de configuracion
    $serverURL = 'http://localhost/webservice/ws2.php?wsdl';

    $cliente = new nusoap_client($serverURL);

    //sí error de conexión:
    $error = $cliente->getError();
    if($error){
        echo "<p> '.$error.' </p>";
        echo '<p style="color:red;'>htmlspecialchars($cliente->getDebug(), ENT_QUOTES).'</p>';
        die();
    }


    echo "<br/>";
    $arreglo2 = $cliente->call('prueba');

    echo "<br/>";
    for( $i=0; $i<3; $i++ ){
            print_r( $arreglo2[$i]['pk'] );
            print_r( $arreglo2[$i]['rol'] );
            print_r( $arreglo2[$i]['descripcion'] );
            echo "<br/>"; 
        }
 ?>

問題は返品です。クライアントに何も返していません。何が起こるかわかりません。多くのフォーラムを読んでいますが、答えが見つかりません。誰かがここで私を助けてくれることを知っているなら、お願いします

タイと私の英語でごめんなさい

4

1 に答える 1