开发者

retrieving information from web service calls

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;}; 开发者_StackOverflow社区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());
}
}
} 


You should look at the documentation of Ksoap2 in order to fully understand what is going on. However, I am going to guess that your Object tempvar can become a java.util.Map, which has methods for reading the keys and extracting values per key.


I actually found an alternative way to do it. I re-structured my web service using cfproperty to define the properties within the web service. And then in the web service, I am using the followings to get the properties,

SoapObject test = (SoapObject) tempResult.get(0);

       String temp_string = (String) test.getProperty("TestKey"); 
       temp_string = temp_string + " " + (String) test.getProperty("TestField");

Now, everything is working the way it should.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜