3

I am trying to retreive an ArrayList from a .NET web service using ksoap.

The data does not seem to be able to enter my coo arraylist.

How can this be solved? Is there anything wrong with my code?

    SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
    SoapSerializationEnvelope envelope =
    new SoapSerializationEnvelope(SoapEnvelope.VER11);
    envelope.dotNet = true;
    envelope.setOutputSoapObject(request);
    HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
    ArrayList <String> coo = new ArrayList <String>();

    try{
        androidHttpTransport.call(bustop_SOAP_ACTION, envelope);

        java.util.Vector<Object> receivedStrings = (java.util.Vector<Object>)envelope.getResponse();
        if(receivedStrings !=null)
        {
            for(Object curStrings : receivedStrings)
            {
                coo.add(curStrings.toString());
            }
        }
    }
    catch(Exception e){}

This is the raw output of the web service:

<?xml version="1.0" encoding="utf-8" ?>
   <ArrayOfAnyType xmlns:xsi="w3.org/2001/XMLSchema-instance"; xmlns:xsd="w3.org/2001/XMLSchema"; xmlns="FYPJWebService.com">;
      <anyType xsi:type="xsd:string">1.278217,103.837517</anyType>
      <anyType xsi:type="xsd:string">1.278300,103.837705</anyType>
      <anyType xsi:type="xsd:string">1.281510,103.840888</anyType>
      <anyType xsi:type="xsd:string">1.285616,103.844446</anyType>
   </ArrayOfAnyType>
ThatGuyInIT
  • 2,239
  • 17
  • 20
weejing
  • 173
  • 2
  • 12

2 Answers2

0

KSoap2. That should help.

azharb
  • 979
  • 6
  • 15
  • Yes i am using KSOAP2 to call the webservice. I am currently trying to call a list of array from the web services. I am trying to store the arraylist's data into the variable coo, but the data cant seem to be stored. Are there any guides on ksoap2 avalible that can assit me? – weejing Jul 11 '11 at 06:29
  • http://www.helloandroid.com/tutorials/using-ksoap2-android-and-parsing-output-data – azharb Jul 11 '11 at 13:40
  • Thanks for the guide, are there any guides on caaling arrays or arraylist webservice too? – weejing Jul 12 '11 at 05:25
  • I'm literally just posting results from google searches. Look around on the internet, implement the code I suggested above and if you run into difficulties, post your code with questions and somebody will help. – azharb Jul 12 '11 at 14:50
0

What I would suggest you is to convert that ArrayList to a String array. You could refer this

You could also convert your ArrayList to a String in Android

Then in the web service code on the server side add some delimiter like "#" that would separate each individual item of your ArrayList and store in a String Array.

On the Android side then you could call the web service like this:

 public String[] call()
 {
    SoapPrimitive responsesData = null; 

    SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME); 

    SoapSerializationEnvelope envelope = new SoapSerializationEnvelope( 
    SoapEnvelope.VER11); 
    envelope.dotNet = true; 
    envelope.setOutputSoapObject(request);

    HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);

    androidHttpTransport.debug = true; 

    try {

    androidHttpTransport.call(SOAP_ACTION, envelope);

    responsesData = (SoapPrimitive) envelope.getResponse(); 
    System.out.println(" --- response ---- " + responsesData); 

    } catch (SocketException ex) { 
    ex.printStackTrace(); 
    } catch (Exception e) { 
    e.printStackTrace(); 
    } 

    System.out.println( " ----" + responsesData );

    String serviceResponse= responsesData .toString(); 


    String[] temp; 
    String delimiter = "#"; 
    temp= serviceResponse.split(delimiter);
    System.out.println( " ---- length ---- " + temp.length); 

    return temp; 

 }      

Hope that helps

Community
  • 1
  • 1
Parth Doshi
  • 4,200
  • 15
  • 79
  • 129