1

这是我的代码:

require_once('library/nusoap/nusoap.php');

$NAMESPACE = 'http://domain.com/';

$server = new nusoap_server();
$server->configureWSDL('cm', $NAMESPACE, 'http://domain.com/webservice.php');

$server->wsdl->addComplexType(
    'Contacts',
    'complexType',
    'struct',
    'all',
    '',
    array(
        'contact_pid' => array('name'=>'contact_pid','type'=>'xsd:int'),
        'contact_pfname' => array('name'=>'contact_pfname','type'=>'xsd:string'),
        'contact_plname' => array('name'=>'contact_plname','type'=>'xsd:string')
    )
);

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

$server->register(
    'fetchAllContacts',
    array('auth_user'=>'xsd:string','auth_pass'=>'xsd:string'),
    array('return'=>'tns:ContactsArray'),
    $NAMESPACE);

function fetchAllContacts($auth_user,$auth_pass)
{
    $authenticate_query = "select * from users_master where user_email='".$auth_user."' and user_password='".md5($auth_pass)."' and user_status='1'";
    $authenticate_user = mysql_query($authenticate_query) or die(mysql_error());
    if(mysql_num_rows($authenticate_user) > 0)
    {
        $row_data = mysql_fetch_array($authenticate_user);
        $select_all_contacts = mysql_query("select * from contacts_master where contact_userid='".$row_data['user_pid']."'") or die(mysql_error());
        if(mysql_num_rows($select_all_contacts) > 0)
        {
            $contact_loop = 0;
            while($row_contacts = mysql_fetch_array($select_all_contacts))
            {
                $contact_array[]['contact_pid'] =   $row_contacts['contact_pid'];
                $contact_array[]['contact_pfname'] =    $row_contacts['contact_pfname'];
                $contact_array[]['contact_plname'] =    $row_contacts['contact_plname'];

                $contact_loop++;
            }
            return $contact_array;
        }
        else
        {
            return array("error" => "No records found!");
        }
    }
    else
    {
        return array("error" => "Error in authentication!");
    }
}

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

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

我遇到的问题是它没有返回任何东西。

4

1 回答 1

0

设置数组值时,您不使用索引。

改变这个:

$contact_array[]['contact_pid']    = $row_contacts['contact_pid'];
$contact_array[]['contact_pfname'] = $row_contacts['contact_pfname'];
$contact_array[]['contact_plname'] = $row_contacts['contact_plname'];

进入:

$contact_array[$contact_loop]['contact_pid']    = $row_contacts['contact_pid'];
$contact_array[$contact_loop]['contact_pfname'] = $row_contacts['contact_pfname'];
$contact_array[$contact_loop]['contact_plname'] = $row_contacts['contact_plname'];

应该做的伎俩。

于 2013-01-07T10:19:25.057 回答