android - How can I make a ksoap2 call in async task? -
i newbie on android development. trying develop application connect .net webservice in order retrieve data. make ksoap2 call async task. how call asyncronus asynctask?
my soapcall class
public class soapcall { public final static string soap_action = "http://www.alpha.net.com/executeebscommand"; public final static string operation_name = "executeebscommand"; public final static string namespace = "http://www.alpha.net.com"; public final static string url = "http://192.168.2.100/ebs2alpha/service.asmx"; public string connection(string command, string commandparameters) throws throwable, throwable { string response = null; soapobject request = new soapobject(namespace, operation_name); request.addproperty("strcommand", command); request.addproperty("strcommandparameters", commandparameters); soapserializationenvelope soapenvelope = new soapserializationenvelope( soapenvelope.ver11); soapenvelope.dotnet = true; soapenvelope.setoutputsoapobject(request); // needed make internet call // allow debugging - needed output request httptransportse androidhttptransport = new httptransportse(url); androidhttptransport.debug = true; // actual part call webservice androidhttptransport.call(soap_action, soapenvelope); // soapresult envelope body. soapobject result = (soapobject) soapenvelope.bodyin; response = result.getproperty(0).tostring(); return response; } }
so far getting response calling connection method in main activity with
soapcall call1= new soapcall(); call1.connection("get_clients", "%");
using asynctask straightforward. here example.
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 make internet call // allow debugging - needed output request httptransportse androidhttptransport = new httptransportse(url); androidhttptransport.debug = true; // actual part call webservice androidhttptransport.call(soap_action, soapenvelope); // soapresult envelope body. soapobject result = (soapobject) soapenvelope.bodyin; response = result.getproperty(0).tostring(); return response; } }
and call task parameters.
mytask mytask = new mytask(); mytask.execute(new string[] {command, commandparameters}); hope help.
Comments
Post a Comment