Android webservice:如何接收字符串数组

时间:2014-11-04 14:12:17

标签: java javascript android arrays eclipse

我的网络服务XML如下:

HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: length

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"       xmlns:xsd="http://www.w3.org/2001/XMLSchema"    xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <GetAllPanelsResponse xmlns="http://SolMonAndroid.org/">
      <GetAllPanelsResult>
        <string>string</string>
        <string>string</string>
      </GetAllPanelsResult>
    </GetAllPanelsResponse>
  </soap:Body>
</soap:Envelope>

如何在我的Android应用程序上接收它作为一个数组?我尝试了以下但是返回的结果是0.(我知道有超过0个条目)

    //panels webservice
public static String[] invokeGetAllPanelsWS(String ON, String SA) {
    String[] returnList = null;

    // Create request to get all the panels
    SoapObject request = new SoapObject(WSDL_TARGET_NAMESPACE, ON);
    // Create envelope
    SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
    //ensures that the envelope is .NET compatible 
    envelope.dotNet = true;
    // Set output SOAP object
    envelope.setOutputSoapObject(request);
    // Create HTTP call object
    HttpTransportSE androidHttpTransport = new HttpTransportSE(SOAP_ADDRESS);

    try {
        // Invoke web service
        androidHttpTransport.call(SA, envelope);
        // Get the response
        SoapObject response = (SoapObject) envelope.getResponse();

        // get the amount of list items
        int intPropertyCount = response.getPropertyCount();
        //creates a new return array
        returnList = new String[intPropertyCount];

        //loops through all the results
        for (int i = 0; i < intPropertyCount; i++) {
            String str = ((String)(response).getPropertyAsString(i));
            returnList[i] = str;
        }
    } catch (Exception e) {
        //should show error screen
        //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
        System.out.println(e.getMessage());
        e.printStackTrace();
        return null;
    } 
    //Return array to calling object
    return returnList;
}

现在我打电话给我的一个主要活动进行测试:

public class WebServiceGetAllPanels extends AsyncTask<Void, Void, String[]> {

    @Override
    protected void onPreExecute() {
        // TODO Auto-generated method stub
        super.onPreExecute();
    }

    @Override
    protected void onPostExecute(String[] result) {
        System.out.println(panelSet.length);
    }

    @Override
    protected String[] doInBackground(Void... arg0) {
        panelSet = Webservice.invokeGetAllPanelsWS("GetAllPanels", "http://SolMonAndroid.org/GetAllPanels");
        return null;
    }
}

0 个答案:

没有答案