Package COM. fairyeye. simple; import android. app. activity; import android. content. intent; import android. OS. bundle; import android. view. view; import android. view. view. onclicklistener; import android. widget. button; import android. widget. edittext; import android. widget. textview; import android. widget. toast; import Org. ksoap2.soapenvelope; import Org. ksoap2.serialization. soapobject; import Org. ksoap2.serialization. Soapserializationenvelope; import Org. ksoap2.transport. httptransportse; public class minisystemactivity extends activity {/** called when the activity is first created. */private edittext username; private edittext userpass; private button btnlogin; private button btnclose; private textview TV; final string soap_action = "http://tempuri.org/HelloWorld"; Private Static final string method_name =" Helloworld "; Private Static final string namespace =" http://tempuri.org/"; Private Static final string url =" http: // 10.0.2.2/webser/webtest. asmx "; @ override public void oncreate (bundle savedinstancestate) {super. oncreate (savedinstancestate); setcontentview (R. layout. main); btnlogin = (button) findviewbyid (R. id. btnlogin); btnclose = (button) findviewbyid (R. id. btnclose); username = (edittext) find Viewbyid (R. id. username); userpass = (edittext) findviewbyid (R. id. userpass); TV = (textview1_findviewbyid(r.id.txt view); btnlogin. setonclicklistener (listener); Call ();} private onclicklistener listener = new onclicklistener () {public void onclick (view v) {// todo auto-generated method stub if (username. gettext (). tostring (). trim (). equals ("222") & userpass. gettext (). tostring (). trim (). equals ("222 ")) {Intent = new intent (); intent. setclass (minisystemactivity. this, testactivity. class); startactivity (intent);} else {toast. maketext (minisystemactivity. this, "the user or password is incorrect! ", Toast. length_long ). show () ;}}; public void call () {try {soapobject request = new soapobject (namespace, method_name); // request. addproperty ("passonstring", "rajapandian"); // This is the soapserializationenvelope envelope = new soapserializationenvelope (soapenvelope. ver11); envelope. DOTNET = true; envelope. setoutputsoapobject (request); httptransportse androidhttptransport = new httptransportse (URL); androidhttptransport. call (soap_action, envelope); object result = (object) envelope. getresponse (); TV. settext (result. tostring ();} catch (exception e) {system. out. println (E. getmessage (); TV. settext (E. getmessage ());}}}
------------------------------- The preceding Implementation calls the helloworld method in. Net webserivce through the kSOAP package method in Android.
1. localhost/127.0.01 cannot be used in the ADT virtual machine. In the virtual machine, 10.0.2.2 is the local address by default. net WebService if it is localhost/webser/webtest. in the android simulator, asmx is 10.0.2.2/webser/webtest/asmx. (test the problem in person)
2. Remember to add androidmanifest. XML to allow Internet access <uses-Permission Android: Name = "android. Permission. Internet"/>
Turn: http://blog.csdn.net/fairyeye/article/details/6672466