php web service return array

 what is web services in php ?

Nusoap is php classes library that is developed by free php script nusoap .A web services that is created with the help of nusoap php classes is called Nusoap web service.Nusoap lib is Free php-script which you can use for web can learn creating web services using php.Creating web service in php  as easy as other code you write in php.Here you will learn how to creare web service in php.This is php web service example using nusoap lib.

web services using php.

  1.  Create new folder and rename it to "server" on your server space
  2. ( local user just create in htdocs. )
  3.  Download Nusoap library from 
  4. nusoap it is zip file
  5. You have to extract the "lib" folder from it and paste to web root(I.E htdocs).
  6.  Now create new php file in sever folder and rename it to "server.php"
  7. Paste the following code in it.
  8. server.php  
        //include required class for build nnusoap web service server
        // Create server object
        $server = new soap_server();
              // configure WSDL
        $server->configureWSDL('PHP Web Services return array', 'urn:returnArray');
        // Complex Type Struct for return array
            'id' => array('id' => 'id', 'type' => 'xsd:string'),
            'firstname' => array('name' => 'firstname', 'type' => 'xsd:string'),
            'lastname' => array('name' => 'lastname', 'type' => 'xsd:string'),
            'email' => array('name' => 'email', 'type' => 'xsd:string')
        array('limit_start' => 'xsd:int','limit_end' => 'xsd:int'),
        array('return' => 'tns:return_array_php'),
        'Returns array data in php web service'
        function get_data($limit_start,$limit_end) 
           /* you can use mysql and your logic here
              this is sample array */
            return $return;
Now Client Side  Steps:
  1.  Now create new php file in sever folder and rename it to "client.php"
  2. Paste the following code in it.
  3. client.php  
      // includes nusoap class
    // Create object
    //change according your server settings
    $client = new nusoap_client('http://localhost:8081/web_service-return_array/server/server.php?wsdl', true);
    //use curl --set here to true
    // Check for an error
    $err = $client->getError();
    if ($err) {
        // error if any
        echo '
    Constructor error
    ' . $err . '
    '; } $result = $client->call('get_data', array('limit_start' => 0,'limit_end'=>5),'','','',true); // fault if any if ($client->fault) { echo ' Fault
        echo '
    '; } else { // Check for errors $err = $client->getError(); if ($err) { // Display the error echo 'Error';
    ' . $err . '
    '; } else { // Display the result if($result!=false) { echo "Results"; foreach($result as $key=>$val) { //go through array print_r($val); } } } }

Buy Me a Beer-If you are like this post

 If you does not have paypal account create free account create account

No comments:

Post a Comment