0

I have a java web service which i want to use with an android client for that am using ksoap. My web service gives an answer which look like this :

java.util.List : "[mobilerestaurantbooking.RMenu@66eb63f8,
mobilerestaurantbooking.RMenu@67f06391,
mobilerestaurantbooking.RMenu@5718f9e6,
mobilerestaurantbooking.RMenu@28be97b6,
mobilerestaurantbooking.RMenu@78da429f]"

that is something like id, name , category,.... and pass it to my application but the output is like anyType{}

this is my code in android

        try {
            aht.call(SOAP_ACTION, soapEnvelope);
            SoapObject response = (SoapObject)soapEnvelope.bodyIn;
            List<String> categories = new ArrayList<String>();
            int count = response.getPropertyCount();

            for(int i = 0; i < count; i++) {
                if(response.getProperty(i) != null)
                    categories.add(response.getProperty(i).toString());
            }

who know what should i do?

3
  • See this link stackoverflow.com/questions/10087480/…. I think it's useful for you. Commented Jan 4, 2013 at 9:20
  • try modifying like this example SoapObject yourResponseObject = (SoapObject) soapEnvelope.bodyIn; SoapObject array = (SoapObject) yourResponseObject .getProperty(0); SoapObject DisplayName= (SoapObject)array .getProperty(0); SoapObject Email= (SoapObject)array .getProperty(1); Commented Jan 4, 2013 at 9:33
  • unfortunately i don't get answer i used like that but i don`t have any response Commented Jan 4, 2013 at 10:23

3 Answers 3

1
public class KSOAP extends Activity 
{
    ListView list;
    ArrayList<String> arraylist = new ArrayList<String>();
    ArrayAdapter<String>  arrayadapter;

    Button btn;
    TextView tv,tv2,tv3; 
    EditText no1,no2;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) 
{ 
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

tv=(TextView)findViewById(R.id.textView1);
tv2=(TextView)findViewById(R.id.textView2);
//tv3=(TextView)findViewById(R.id.textView3);

list=(ListView)findViewById(R.id.listView1);

no1=(EditText)findViewById(R.id.editText1);
no2=(EditText)findViewById(R.id.editText2);

btn =(Button)findViewById(R.id.button1);
btn.setOnClickListener(new OnClickListener() {

    @Override
    public void onClick(View v) {
        // TODO Auto-generated method stub


        String NAMESPACE = "http://tempuri.org/" ;    
        //"http://vladozver.org/";
        String METHOD_NAME = "GetStringList"; //"GetSumOfTwoIntsList";//
        String SOAP_ACTION = "http://tempuri.org/GetStringList";  
        //"http://vladozver.org/GetSumOfTwoInts";
        String URL = "http://192.168.0.203/recharge_service/service.asmx";
        //"http://192.168.0.203/Recharge_Service/Service.asmx";


        SoapObject Request = new SoapObject(NAMESPACE, METHOD_NAME);

//      PropertyInfo pi = new PropertyInfo();
//      pi.setName("Operand1");
//      pi.setValue(Integer.parseInt(no1.getText().toString()));
//      pi.setType(int.class);
//      Request.addProperty(pi);
//
//      PropertyInfo pi2 = new PropertyInfo();
//      pi2.setName("Operand2");
//      pi2.setValue(Integer.parseInt(no2.getText().toString()));
//      pi2.setType(int.class);
//      Request.addProperty(pi2);


        SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
        envelope.dotNet = true;
        envelope.setOutputSoapObject(Request);
        try
        {
        AndroidHttpTransport transp = new AndroidHttpTransport(URL);
        transp.call(SOAP_ACTION, envelope);

        SoapObject obj1 = (SoapObject) envelope.bodyIn;

        SoapObject obj2 =(SoapObject) obj1.getProperty(0);


        for (int i = 0; i< obj2.getPropertyCount(); i++) 
            { 
                // int id1 = Integer.parseInt(obj2.getProperty(0).toString());
               String id1=obj2.getProperty(0).toString();

               if(id1 != "")
               { 
                 arraylist.add( id1);   

               }
                /* tv3.setText(id3);*/
            }


        }
        catch(Exception e)
        { tv.setText(e.toString());
        e.printStackTrace();
        }

        //tv.setText(""+ count);



               list.setAdapter(arrayadapter);
    }
});

        arrayadapter = new ArrayAdapter<String>( this, 
        android.R.layout.simple_list_item_1, arraylist );
       list.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
                long arg3) {
            // TODO Auto-generated method stub

        }
    });

}


}
Sign up to request clarification or add additional context in comments.

1 Comment

Good solution, but you have to correct the index of obj2,getProerty(0) and use i instead of 0
0

and also i do it like it but i dont have any record in menu class.

SoapObject result = (SoapObject) soapEnvelope.bodyIn;


Menu[] menus = new Menu[result.getPropertyCount()];

for (int i = 0; i < menus.length; i++) { 
   SoapObject so = (SoapObject) result.getProperty(0); 
   Menu s = new Menu(); 
   s.setID(Integer.parseInt(so.getProperty(0).toString())); 
   s.setName(so.getProperty(1).toString()); 
   s.setPrice(Double.parseDouble(so.getProperty(2).toString())); 
   s.setCategory(so.getProperty(3).toString()); 
   menus[i] = s; 
 }

1 Comment

when change it SoapObject result = (SoapObject) soapEnvelope.bodyIn; to SoapObject result = (SoapObject) soapEnvelope.getResponce; the length is 0
0
SoapObject result = (SoapObject) soapEnvelope.bodyIn;
Menu[] menus = new Menu[result.getPropertyCount()];
for (int i = 0; i < menus.length; i++) {
SoapObject so = (SoapObject) result.getProperty(i);
    ID = so.getProperty(0).toString();
    Name = so.getProperty(1).toString();
    price = so.getProperty(2).toString();
    Catagory = so.getProperty(3).toString();
}

and after get the result in one object:

SoapPrimitive so = (SoapPrimitive) so.getProperty(1);
firstlist[i] = so.getPropertyAsString(0).toString();

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.