我已经定义了一个Web服务,从我的MySQL数据库返回数据的数组。WSDL返回复杂类型
我已经用php编写了web服务。
现在我已经定义的复杂类型,如下所示:
$server->wsdl->addComplexType(
'Category',
'complexType',
'struct',
'all',
'',
array(
'category_parent_id' => array('name' => 'category_parent_id', 'type' => 'xsd:int'),
'category_child_id' => array('name' => 'category_child_id', 'type' => 'xsd:int'),
'category_list' => array('name' => 'category_list', 'type' => 'xsd:int')
)
);
上述复杂类型是我数据库中表中的一行。现在
我的功能必须把这些行的一组让我怎么实现同样
我的代码如下:
require_once('./nusoap/nusoap.php');
$server = new soap_server;
$server->configureWSDL('productwsdl', 'urn:productwsdl');
// Register the data structures used by the service
$server->wsdl->addComplexType(
'Category',
'complexType',
'struct',
'all',
'',
array(
'category_parent_id' => array('name' => 'category_parent_id', 'type' => 'xsd:int'),
'category_child_id' => array('name' => 'category_child_id', 'type' => 'xsd:int'),
'category_list' => array('name' => 'category_list', 'type' => 'xsd:int')
)
);
$server->register('getaproduct', // method name
array(), // input parameters
//array('return' => array('result' => 'tns:Category')), // output parameters
array('return' => 'tns:Category'), // output parameters
'urn:productwsdl', // namespace
'urn:productwsdl#getaproduct', // soapaction
'rpc', // style
'encoded', // use
'Get the product categories' // documentation
);
function getaproduct()
{
$conn = mysql_connect('localhost','root','');
mysql_select_db('sssl', $conn);
$sql = "SELECT * FROM jos_vm_category_xref";
$q = mysql_query($sql);
while($r = mysql_fetch_array($q))
{
$items[] = array('category_parent_id'=>$r['category_parent_id'],
'category_child_id'=>$r['category_child_id'],
'category_list'=>$r['category_list']);
}
return $items;
}
// 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);
是的,我知道这个格式是不正确的,但我的家伙在粘贴由编辑器提供的代码块中的代码,但它似乎并没有工作。 如果有些能告诉我为什么还是有人可以对其进行编辑对我来说这将是巨大的 – 2010-01-12 03:36:47