ksoap kütüphanesini arkaplanda çalıştırmalısın. Servise bağlanma süreci zaman alacağından diğer işlemleri geciktirecektir. AsyncTask işini görecektir.
AsyncTask class:
public class MyTask extends AsyncTask<String, Integer, String>{
@Override
protected String doInBackground(String... params) {
String response = null;
SoapObject Request = new SoapObject(NAMESPACE, OPERATION_NAME);
Request.addProperty("strCommand", params[0]);
Request.addProperty("strCommandParameters", params[1]);
SoapSerializationEnvelope soapEnvelope = new SoapSerializationEnvelope(
SoapEnvelope.VER11);
soapEnvelope.dotNet = true;
soapEnvelope.setOutputSoapObject(Request);
// Needed to make the internet call
// Allow for debugging - needed to output the request
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
androidHttpTransport.debug = true;
// this is the actual part that will call the webservice
androidHttpTransport.call(SOAP_ACTION, soapEnvelope);
// Get the SoapResult from the envelope body.
SoapObject result = (SoapObject) soapEnvelope.bodyIn;
response = result.getProperty(0).toString();
return response;
}
}
Uygulaman içerisinde şu şekilde çağırabilirsin:
MyTask myTask = new MyTask();
myTask.execute(new String[] {Command, CommandParameters});
ya da
new MyTask().execute(new String[] {Command, CommandParameters});