PHP Web服务返回数组,但无法从Java客户端获取数组


php webservice return array,but can't get the array from java client

我写了一个php web服务。函数如下:

function get_device_info(){
    $conn= mysql_connect("localhost", "admin", "123456") or die("Could not connect: " . mysql_error());
    mysql_select_db('devices',$conn);
    $sql="select id,description,hostname,status_rec_date,availability from host";
    $query=mysql_query($sql);
    while($myrow = mysql_fetch_array($result)){
        $host_msg[$i]=$myrow;
        $i++;
    }
   return $host_msg;
   mysql_close($conn);
}

然后我用java编写了soap客户端来调用这个Web服务。

import java.net.MalformedURLException;  
import java.rmi.RemoteException;  
import javax.xml.rpc.ServiceException;  
import org.apache.axis.client.Call;  
import org.apache.axis.client.Service;
public class javasoapclient {
    public static void main(String[] args) throws ServiceException, MalformedURLException, RemoteException {  
        String serviceUrl = "http://192.168.1.44/webservices/serverSoap.php";  
        Service service = new Service();  
        Call call = (Call) service.createCall();  
        call.setTargetEndpointAddress(new java.net.URL(serviceUrl));  
        call.setOperationName("get_device_info");
        String reVal = call.invoke(new Object[] {}).toString();
        System.out.println(reVal);
    }
}

它无法获取数组。我是PHP的新手。谁能帮忙?

提前感谢!

这不是 SOAP 的工作方式。SOAP 具有独特的结构:

<?xml version="1.0"?>
<soap:Envelope
xmlns:soap="http://www.w3.org/2001/12/soap-envelope"
soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding">
<soap:Body xmlns:m="http://www.example.org/stock">
  <m:GetStockPrice>
    <m:StockName>IBM</m:StockName>
  </m:GetStockPrice>
</soap:Body>
</soap:Envelope>

您要返回的只是一个简单的数组。

为了在java中获取此数组,您最好使用HttpClient。