Today, from the book and csdn to find a few examples of Android call WebService, these examples from the code point of view, there is no error, but the run is not successful. This paper analyzes the writing of the Android calling Web interface, and finds that these examples do not open a thread at the time of the call to run the problem. The following is CSDN download the example "Android query phone number" of the major changes to the code, I hope to learn about the Android beginner is helpful.
futuretask<string> futuretask = new futuretask<string> (new callable<string> () {@Overridepublic String call () throws exception{try{//calls Webservicetransport.call (SOAPAction, envelope); if (Envelope.getresponse ()! = NULL) {//Gets the returned data soapobject object = (soapobject) envelope.bodyin;//Gets the results returned by string result = Object.getproperty (0). ToString (); return result;}} catch (Exception e) {e.printstacktrace ();} return null;}}); New Thread (Futuretask). Start ();//WebService The returned results are displayed in TextView try{string result=futuretask.get (); Resultview.settext (result);} catch (Interruptedexception e) {//TODO auto-generated catch Blocke.printstacktrace ();} catch (Executionexception e) {// TODO auto-generated catch Blocke.printstacktrace ();}
Csdn download Some questions about the Android program call WebService run unsuccessfully