从webservice获取ANDROID中SoapObject的所有数据

时间:2016-01-31 08:34:06

标签: android web-services listview

    client = new SoapObject(NAMESPACE, METHOD_NAME);
    sse.setOutputSoapObject(client);
    sse.bodyOut = client;
    androidHttpTransport.call(SOAP_ACTION, sse);

    // This step: get file XML
    responseBody = (SoapObject) sse.getResponse();
    // remove information XML,only retrieved results that returned
    responseBody = (SoapObject) responseBody.getProperty(1);
    // get information XMl of tables that is returned
    table = (SoapObject) responseBody.getProperty(0);
    //Get information each row in table,0 is first row
    tableRow = (SoapObject) table.getProperty(0);
    setapp.appointment_no = tableRow.getProperty("appointmentno").toString();

问题是它只返回第一条记录并在textview中显示它我想要返回所有记录并在listView中显示它。

我认为因为这条线

tableRow = (SoapObject) table.getProperty(0);

我可以在List中获得所有结果吗?

这是我的布局文件

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent">

    <TextView
        android:id="@+id/txt33"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        />


</LinearLayout>

1 个答案:

答案 0 :(得分:0)

Following is the code block from my old project.
SoapObject request = new SoapObject(WSDL_TARGET_NAMESPACE,OPERATION_NAME);
//add property
PropertyInfo pi=new PropertyInfo();
pi.setName("EmpName");
pi.setValue(Employee_ID);
pi.setType(String.class);
request.addProperty(pi);

//set the envelope
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
        SoapEnvelope.VER11);
envelope.dotNet = true;

envelope.setOutputSoapObject(request);


HttpTransportSE httpTransport = new HttpTransportSE(SOAP_ADDRESS);
Object response=null;
try
{   
    //Give a call
    httpTransport.call(SOAP_ACTION, envelope);
    //Hold the the response
    response = envelope.getResponse();

    SoapObject result = (SoapObject) envelope.getResponse();
    SoapObject root = (SoapObject) result.getProperty(0);
    SoapObject emp = (SoapObject) root.getProperty("InfraWiseDetails");

    for (int i = 0; i < emp.getPropertyCount(); i++) {
        SoapObject emp1 = (SoapObject) emp.getProperty(i);
        String name = emp1.getProperty("EmpName").toString();
        String id = emp1.getProperty("Employee_ID").toString();

        //use String variables name and id as you wants
    }
}
catch (Exception exception)
{
    //exception
}

有关更详细的教程,请访问here