Sunday, February 3, 2013

php nusoap multi input and return



<?php
// Pull in the NuSOAP code
require_once('nusoap.php');
// Create the server instance
$server = new soap_server();
// Initialize WSDL support
$server->configureWSDL('hellowsdl2', 'urn:hellowsdl2');
// Register the data structures used by the service
$server->wsdl->addComplexType(
    'authentication',
    'complexType',
    'struct',
    'all',
    '',
    array(
        'username' => array('name' => 'username', 'type' => 'xsd:string'),
        'password' => array('name' => 'password', 'type' => 'xsd:string')
    )
);
$server->wsdl->addComplexType(
    'login_result',
    'complexType',
    'struct',
    'all',
    '',
    array(
        'result' => array('name' => 'result', 'type' => 'xsd:boolean'),
        'desc' => array('name' => 'desc', 'type' => 'xsd:string')
    )
);
// Register the method to expose
$server->register('hello',                    // method name
    array('person' => 'tns:authentication'),          // input parameters
    array('return' => 'tns:login_result'),    // output parameters
    'urn:hellowsdl2',                         // namespace
    'urn:hellowsdl2#hello',                   // soapaction
    'rpc',                                    // style
    'encoded',                                // use
    'Greet a person entering the sweepstakes'        // documentation
);
// Define the method as a PHP function
function hello($person) {
    $desc = 'login, username:' . $person['username'] .
                '. password ' . $person['password'] .'.';
   
    $result = $person['username'] == 'vilaivat';

    return array(
                'result' => $result,
                'desc' => $desc
                );
}
// Use the request to (try to) invoke the service
$HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : '';
$server->service($HTTP_RAW_POST_DATA);
?>

No comments:

Post a Comment