I would like to learn how to use webSservices with Android.
At the moment, I have a server with the wsdl file and I am able to call a desired Webservice from.
My problem is that I got the response from the server and I would like to extract some informations which are interessant for me, for example the user id or something like that.
Here is my code:
public class TestBookSoapActivity extends Activity {
private static final String SOAP_ACTION = "JournalArticles";
private static final String METHOD_NAME = "JournalArticles";
private static final String NAMESPACE = "http://api.mdpi.com/ws/";
private static final String URL = "http://api.mdpi.com/ws/server.php";
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
executeAppelSOAP();
}
private void executeAppelSOAP() {
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
request.addProperty("JournalID", 1);
request.addProperty("Volume", 12);
request.addProperty("Issue", 1);
SoapSerializationEnvelope enveloppe = new SoapSerializationEnvelope(SoapEnvelope.VER11);
enveloppe.setOutputSoapObject(request);
AndroidHttpTransport androidHttpTransport = new AndroidHttpTransport (URL);
try {
androidHttpTransport.call(SOAP_ACTION, enveloppe);
Object resultat = enveloppe.getResponse();
System.out.println(" Journal Articles= " + resultat.toString());
} catch(Exception e) {
e.printStackTrace();
System.out.println("Problem");
}
}
Could I use the enveloppe.parse() method and if so, how?
Thank you.
There are two steps you should take:
About 1…
I prefer HttpTransportSE so instead of:
use:
Then instead of:
use:
You can also check with the debugger how response looks like. More details you can read in answers to this question.
About 2…
You can use any XML parser. I prefer SAX for performance reasons. Here is an Android example: how to parse XML in Android
Regards,
Dragan