在android中使用SOAP从webservice获取多个数据

时间:2011-09-29 07:46:38

标签: android soap

我在Android中使用SOAP从Web服务获取单个数据并显示良好。但是当我需要从Web服务中检索多组值时..我怎么能这样做?对于ex.from webservice。,我得到10一组学生记录与字段stu.Name,stuRegno。,stuAge.After得到这个回应。,我需要解析它存储到本地数据库与相应的字段名称。我怎么能这样做?

我的代码:

 public class Main extends Activity {
    private static final String METHOD_NAME = "TopGoalScorers";
     private static final String SOAP_ACTION = "http://footballpool.dataaccess.eu/data/TopGoalScorers";
     private static final String NAMESPACE = "http://footballpool.dataaccess.eu";
     private static final String URL = "http://footballpool.dataaccess.eu/data/info.wso?WSDL";

    //Called when the activity is first created. 
    @Override
    public void onCreate(Bundle icicle) {
        super.onCreate(icicle);
        setContentView(R.layout.main);

            //Buttons deaktiviert alles automatisch

            SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
            request.addProperty("iTopN", 3);// username von Preferences abgeholt
            //request.addProperty("intB", 4);


            SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
            Toast.makeText(getApplicationContext(), request.toString(), Toast.LENGTH_LONG).show();
            envelope.setOutputSoapObject(request);
            AndroidHttpTransport androidHttpTransport = new AndroidHttpTransport (URL);             
            try {
                androidHttpTransport.call(SOAP_ACTION, envelope);
                //Parse Response
                SoapObject resultsRequestSOAP = (SoapObject) envelope.getResponse();
                String xy = resultsRequestSOAP.getProperty(0).toString();
                ((TextView)findViewById(R.id.lblStatus)).setText(xy); 


            } catch(Exception E) {

                ((TextView)findViewById(R.id.lblStatus)).setText("ERROR:" + E.getClass().getName() + ": " + E.getMessage());

            }
    }

    }  

1 个答案:

答案 0 :(得分:0)

我不明白你的问题是什么。您需要将resultsRequestSOAP转换为适当的数据格式(例如String)并解析它(例如通过SAX),并在解析器中收集容器中的所有数据(例如List)。