我在 php 中创建了一个 Web 服务,它以多维数组的形式返回数据,但问题是如何在 .net 中使用它。我知道使用以一维数组返回数据但不了解多维数组的 Web 服务,我在下面包含了代码,请帮助我
服务器端 php 文件
<?php
require_once('lib/nusoap.php');
$server = new soap_server();
$server->configureWSDL('servCarRent', 'urn:servCarRent');
$server->wsdl->addComplexType('getAllKeyData','complexType','array','all','',
array(
'KeyId'=> array('name'=>'KeyId', 'type' =>'xsd:int'),
'KeyName'=> array('name'=>'KeyName', 'type' =>'xsd:string'),
'IsAvailable'=> array('name'=>'IsAvailable', 'type' =>'xsd:int'),
'NoOfKeys'=> array('name'=>'NoOfKeys', 'type' =>'xsd:int')
)
);
$server->wsdl->addComplexType(
'MySoapObjectArray',
'complexType',
'array',
'',
'SOAP-ENC:Array',
array(),
array(array('ref'=>'SOAP-ENC:arrayType','wsdl:arrayType'=>'tns:getAllKeyData[]')),
'tns:getAllKeyData'
);
$server->register(
'getAllKeys',
array(),
array('return'=>'tns:MySoapObjectArray'),
$ns,
false,
'rpc',
false,
'Processes an array of MySoapObjects and returns one of them');
function getAllKeys()
{
$con=mysql_connect('localhost','root','pass')or die("cannot connect");
mysql_select_db('mydb')or die("cannot select db");
$sql = 'Select * from KeyTable';
$result=mysql_query($sql,$con);
$out=array();
while($row = mysql_fetch_assoc($result))
{
$out[]=$row;
}
return $out;
}
$HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : '';
$server->service($HTTP_RAW_POST_DATA);
exit();
?>
客户端php文件
<?php
require_once('lib/nusoap.php');
$client = new nusoap_client('http://www.mydomainname.com/new/servCarRent.php?wsdl');
$err = $client->getError();
if ($err) {
echo '<h2>Constructor error</h2><pre>' . $err . '</pre>';
}
$response = $client->call('getAllKeys');
if($client->fault)
{
echo '<h2>Fault</h2><pre>';
echo '</pre>';
}
else
{
$err = $client->getError();
if ($err) {
echo '<h2>Error</h2><pre>' . $err . '</pre>';
}
else
{
echo '<h2>Result</h2><pre>';
print_r($response);
echo '</pre>';
}
}
?>
如果我运行客户端文件,那么我可以访问数据,如下所示
Result
Array
(
[0] => Array
(
[0] => 1
[1] => 20577369Y
[2] => 1
[3] => 2
)
[1] => Array
(
[0] => 2
[1] => 63337921S
[2] => 1
[3] => 2
)
)
但我想在 .net 中访问它,我在我的 .net 项目中包含了网络引用并将其命名为 webSerCarRent ,我尝试如下但在 XML 文档中出现错误
webSerCarRent.servCarRent scr = new webSerCarRent.servCarRent();
webSerCarRent.getAllKeyData[] gakd = new webSerCarRent.getAllKeyData[10];
gakd = scr.getAllKeys();
for (int i = 0; i < gakd.Length; i++)
{
string kname = gakd[i].KeyName;
}
请帮我