retrieving information from web service calls
Posted
by Monte Chan
on Stack Overflow
See other posts from Stack Overflow
or by Monte Chan
Published on 2010-05-16T03:10:30Z
Indexed on
2010/05/16
3:20 UTC
Read the original article
Hit count: 339
android
|web-services
Hi all,
I am trying to retrieve information from a web service call. The following is what I have so far. In my text view, it is showing
Map {item=anyType{key=TestKey; value=2;}; item=anyType{key=TestField; value=adsfasd; };}
When I ran that in the debugger, I can see the information above in the variable, tempvar. But the question is, how do I retrieve the information (i.e. the actual values of "key" and "value" in each of the array positions)? Yes, I know there is a lot going on in onCreate and I will fix it later.
Thanks in advance, Monte
My codes are as follows,
import java.util.Vector;
import android.app.Activity; import android.os.Bundle; import android.widget.TextView;
import org.ksoap2.SoapEnvelope; import org.ksoap2.serialization.SoapObject; import org.ksoap2.serialization.SoapSerializationEnvelope; import org.ksoap2.transport.AndroidHttpTransport;
public class ViewHitUpActivity extends Activity { private static final String SOAP_ACTION = "test_function"; private static final String METHOD_NAME = "test_function"; private static final String NAMESPACE = "http://www.monteandjanicechan.com/"; private static final String URL = "http://www.monteandjanicechan.com/ws/test_ws.cfc?wsdl"; // private Object resultRequestSOAP = null; private TextView tv;
/** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main);
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME); tv = (TextView)findViewById(R.id.people_view);
//SoapObject request.addProperty("test_item", "1"); SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11); envelope.setOutputSoapObject(request);
AndroidHttpTransport androidHttpTransport = new AndroidHttpTransport(URL); try { androidHttpTransport.call(SOAP_ACTION, envelope); /* resultRequestSOAP = envelope.getResponse(); Vector tempResult = (Vector) resultRequestSOAP("test_functionReturn"); */ SoapObject resultsRequestSOAP = (SoapObject) envelope.bodyIn;
Vector tempResult = (Vector) resultsRequestSOAP.getProperty("test_functionReturn");
int testsize = tempResult.size();
// SoapObject test = (SoapObject) tempResult.get(0);
//String[] results = (String[]) resultRequestSOAP;
Object tempvar = tempResult.elementAt(1);
tv.setText(tempvar.toString()); } catch (Exception aE) { aE.printStackTrace (); tv.setText(aE.getClass().getName() + ": " + aE.getMessage()); } } }
© Stack Overflow or respective owner