How can I call more than one web service at once or one by one in Android? Because if I add two properties then an error occurs. I use KSOAP2 for calling the webservice.
Asked
Active
Viewed 1,441 times
2 Answers
1
You can use Mutlitple AsyncTask to carry out the parallel webservice call. so it will be calling multiple webservice at once. now if you want to do one by one then in single asynctask you can do it after getting response of the previous one.
for AsycTask please refer this link

Community
- 1
- 1

Dinesh Prajapati
- 9,274
- 5
- 30
- 47
0
call the Asynctask for the webservice to get the value of background process..
SoapTask task = new SoapTask();
task.execute();
public class SoapTask extends AsyncTask<Void, Void, Void> {
@Override
protected void onPreExecute() {
}
@Override
protected Void doInBackground(Void... urls) {
Live_Price();
return null;
}
@Override
protected void onPostExecute(Void result) {
if(!error){
try {
Object mObject = response.getProperty(0);
float str = Float.parseFloat(mObject.toString());
float gold = (float) (str / 31.10);
Object mObjectsilver = responseSilver;
float str1 = Float.parseFloat(mObjectsilver.toString());
float silver = (float) (str1 / 31.10);
// U just the get the value from the response like above and print it..
} catch (Exception e) {
e.printStackTrace();
}
}else {
System.out.println("server side problem");
}
}
}
In that code u want to get two url, username, userpassword and just call the simple method and get the response of webservices to give the values. and the response variable declare the global to simply use in any mothods..
public void Live_Price(){
try {
androidHttpTransport.call(SOAP_ACTION, envelope);
response = (SoapObject) envelope.getResponse();
Log.d("myApp","call..ss..>"+ response.toString());
} catch (Exception e) {
error = true;
e.printStackTrace();
}
try {
androidHttpTransportsilver.call(SOAP_ACTIONsilver, envelopesilver);
responseSilver = (SoapPrimitive) envelopesilver.getResponse();
Log.d("myApp","call..ss..>"+ responseSilver.toString());
} catch (Exception e) {
error = true;
e.printStackTrace();
}
}

Gorgeous_DroidVirus
- 320
- 5
- 20