开发者

How to call a .net web service that returns an ArrayList to Android

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 <Str开发者_JAVA百科ing> 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>


KSoap2. That should help.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜