asp.net - How to call 2 web services after clicking button in android? -
i have android application suppose save transaction in 1 database , update balance in database calling 2 seperate web methods. first web method called second web method not called.
asynctask code
public class transaction extends asynctask<string,void,boolean> { private string finalbalance1 = "", price1 = "", pname = "", pnric = "", pclass = "", sno = ""; public transaction(string price1, string pname, string pnric, string pclass, string sno, string finalbalance1) { super(); this.finalbalance1 = double.tostring(finalbalance); this.price1 = double.tostring(sprice); this.pname = sra.studentname; this.pnric = sra.studentnric; this.pclass = sra.studentclass; this.sno = logger.stallno; } @override protected boolean doinbackground (string...url) { boolean = true; httpclient httpclient = new defaulthttpclient(); httppost httppost = new httppost("http://152.226.152.175/nco/webservice.asmx/insertstudenttransaction"); try { list<namevaluepair> namevaluepairs = new arraylist<namevaluepair>(5); namevaluepairs.add(new basicnamevaluepair("nric", pnric)); namevaluepairs.add(new basicnamevaluepair("name", pname)); namevaluepairs.add(new basicnamevaluepair("class", pclass)); namevaluepairs.add(new basicnamevaluepair("stallno", sno)); namevaluepairs.add(new basicnamevaluepair("amountspent", price1)); httppost.setentity(new urlencodedformentity(namevaluepairs)); httpresponse response = httpclient.execute(httppost); httpentity entity = response.getentity(); inputstream in = entity.getcontent(); bufferedreader reader = new bufferedreader(new inputstreamreader(in, "utf-8"), 8); stringbuilder sb = new stringbuilder(); string line = null; while ((line = reader.readline()) != null) { system.out.println(line); } } catch (clientprotocolexception e) { = false; } catch (ioexception e) { = false; } return good; } protected void onpostexecute (boolean good) { if(good == true) { httpclient httpclient = new defaulthttpclient(); httppost httppost = new httppost("http://152.226.152.175/nco/webservice.asmx/updateparticulars"); try { list<namevaluepair> namevaluepairs = new arraylist<namevaluepair>(4); namevaluepairs.add(new basicnamevaluepair("nric", pnric)); namevaluepairs.add(new basicnamevaluepair("fixedamount", finalbalance1)); namevaluepairs.add(new basicnamevaluepair("name", pname)); namevaluepairs.add(new basicnamevaluepair("class", pclass)); httppost.setentity(new urlencodedformentity(namevaluepairs)); httpresponse response = httpclient.execute(httppost); httpentity entity = response.getentity(); inputstream in = entity.getcontent(); bufferedreader reader = new bufferedreader(new inputstreamreader(in, "utf-8"), 8); stringbuilder sb = new stringbuilder(); string line = null; while ((line = reader.readline()) != null) { system.out.println(line); } } catch (clientprotocolexception e) { = false; }catch (ioexception e) { = false; } } } } }
you should use asynctask instead thread here, using 2 seperate asynctask, can call second task in first one's onpostexecute() method.
pls check this: http://developer.android.com/reference/android/os/asynctask.html
Comments
Post a Comment