Results 1 to 4 of 4

Thread: Webservices with php

  1. #1
    Join Date
    Jun 2004
    Posts
    296
    Rep Power
    0

    Default Webservices with php

    Having a little problem trying to create Document Style web services. Nusoap is wonderful but it doesnt seem to allow the creation of complex types within complex types. PHP 5 has all this wonderful soap stuff, however it seems to be limited in some ways, for one I have not been able to find a way to make it generate wsdl file dynamically. Any one out there able to provide me with an alternative or a way to get around these limitations?

  2. #2
    Join Date
    Jun 2004
    Posts
    296
    Rep Power
    0

    Default

    Trying to define a webservice that will take any number of a particular complex types within a complex type using nusoap. Based on examples I have seen on the web the following should work, however the soap message being sent to the server is missing the the telephone elements.

    Server:
    PHP Code:
    <?
    /* load NuSOAP library */
    require_once 'nusoap.php';
    require_once 
    'Tools.inc';

    // create server
    $SoapServer = new soap_server();

    // wsdl generation
    $SoapServer->configureWSDL('Echo''http://www.revelex.com/soap'false'document');
    $SoapServer->wsdl->schemaTargetNamespace 'http://www.revelex.com/soap';
    $SoapServer->wsdl->addComplexType('telephoneNumber',
                                      
    'complexType',
                                      
    'struct',
                                      
    'all',
                                      
    '',
                                      array(
    'area'     => array('name' => 'area',
                                                                
    'type' => 'xsd:string'
                                                                
    ),
                                            
    'exchange' => array('name' => 'exchange',
                                                                
    'type' => 'xsd:string'
                                                                
    ),
                                            
    'number'   => array('name' => 'number',
                                                                
    'type' => 'xsd:string'
                                                                
    )
                                            )
    );

    $SoapServer->wsdl->addComplexType('telephoneNumbers',
                                      
    'complexType',
                                      
    'struct',
                                      
    'sequence',
                                      
    '',
                                      array (
    'telephoneNumber' => array ('name' => 'telephoneNumber',
                                                                         
    'type' => 'tns:telephoneNumber'
                                                                         
    )
                                            )
                                      );

    // register method
    $SoapServer->register('doEcho',
                          array(
    'name'      => 'xsd:string',
                                
    'age'       => 'xsd:int',
                                
    'telephones'=> 'tns:telephoneNumbers'
                                
    ),
                          array(
    'name'      => 'xsd:string',
                                
    'age'       => 'xsd:int',
                                
    'telephone' => 'tns:telephoneNumber'
                                
    ),
                          
    'http://www.revelex.com/soap',
                          
    false,
                          
    'document',
                          
    'literal',
                          
    'Echos back the data given to it, not very useful!'
                          
    );

    // method code (get DB result)
    function doEcho ($name$age$telephones) {
        if (
    is_string($name) and is_numeric($age)) {
            
    // return data
            //return new soap_fault('Server', '', "{$telephoneNumber[0]['area']}");
            
    return array ('name' => $name'age' => $age'telephone' => $telephones['telephoneNumber']);
        }
        
    // we accept only a string and a int.
        
    else {
          return new 
    soap_fault('Client''''Service requires the parameters name (string), age (integer).');
        }
      }

    // pass incoming (posted) data
    $SoapServer->service($HTTP_RAW_POST_DATA)
    ?>
    Client:
    PHP Code:
    <?php
    require_once 'nusoap.php';
    require_once 
    'Tools.inc';

    /*ini_set('display_errors', '1');
    error_reporting(E_ALL);
    function my_handler($no, $str) {
      echo "$no: $str <br/>";
    }

    set_error_handler('my_handler');
    */

    $client = new soap_client('http://dev/www.revelex.com/adennis/main/tmp/soap.rvlx?wsdl'true);
    $err $client->getError();
    if (
    $err) {
        echo 
    '<h2>Constructor error</h2><pre>' $err '</pre>';
    }

    $number[] = array('area'     => '954',
                                  
    'exchange' => '578',
                                  
    'number'   => '3220'
                                  
    );

    $params = array('name'       => 'Alex',
                    
    'age'        => 23,
                    
    'telephones' => array('telephoneNumber' => $number)
                   );

                   
    //Tools::printArray($params);
    echo $client->_getProxyClassCode();
    $proxy $client->getProxy();
    $result $proxy->doEcho($params);

    //$result = $client->call('doEcho', array('parameters' => $params));

    echo '<h2>Debug</h2><pre>' htmlspecialchars($proxy->debug_strENT_QUOTES) . '</pre>';

    Tools::printArray($proxy->request);
    Tools::printArray($proxy->response);

    if (
    $proxy->fault) {
        echo 
    '<h2>Fault (This is expected)</h2><pre>'print_r($result); echo '</pre>';
    } else {
        
    $err $proxy->getError();
        if (
    $err) {
            echo 
    '<h2>Error</h2><pre>' $err '</pre>';
        } else {
            echo 
    '<h2>Result</h2><pre>'print_r($result); echo '</pre>';
        }
    }

    ?>
    Generate Soap Request:
    Code:
    <?xml version="1.0" encoding="ISO-8859-1"?><SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:tns="http://www.revelex.com/soap"><SOAP-ENV:Body><doEcho xmlns=""><name xmlns="">Alex</name><age xmlns="">23</age><telephones xmlns=""><telephoneNumber xmlns=""></telephoneNumber></telephones></doEcho></SOAP-ENV:Body></SOAP-ENV:Envelope>

  3. #3
    Join Date
    Dec 2002
    Posts
    500
    Rep Power
    0

    Default

    i cant see what is wrong with the code the only part that looks suspect is the array append here:
    PHP Code:
    // are the double brackets here correct
    $number/*[]*/ = array('area'     => '954',
                                  
    'exchange' => '578',
                                  
    'number'   => '3220'
                                  
    ); 
    all the examples have exit(); after this line :

    PHP Code:
    $SoapServer->service($HTTP_RAW_POST_DATA);
    /*exit();*/ 
    Last edited by icymint3; Dec 26, 2006 at 07:04 PM.
    Cultured in Aggression and Koding like a Warrior!!
    “Common sense is instinct. Enough of it is genius.” - George Bernard Shaw.
    "The significant problems we face cannot be solved by the same level of thinking that created them." - Albert Einstein

  4. #4
    Join Date
    Jun 2004
    Posts
    296
    Rep Power
    0

    Default

    The reason I am using array is because i want to be able to send multiple 'telephoneNumber' elements. Thats what Im trying figure out how to do.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •