Android development, need to connect webservice, before you want to use the jar package provided by Google,: Http://pan.baidu.com/s/1hqMTUHe
Download it and paste it into the Libs folder:
There are a lot of similar methods on the Internet, I tried a lot of no success, and finally found that I downloaded the jar package has a problem that I have been stuck where.
First Add network permissions:
<uses-permission android:name="android.permission.INTERNET"/>
This is all code, including obtaining data from remote WebService and displaying it in a ListView:
Package Com.example.webservice;import java.io.ioexception;import java.util.arraylist;import java.util.List; Import Org.ksoap2.soapenvelope;import Org.ksoap2.soapfault;import Org.ksoap2.serialization.soapobject;import Org.ksoap2.serialization.soapserializationenvelope;import Org.ksoap2.transport.httptransportse;import Org.xmlpull.v1.xmlpullparserexception;import Android.os.bundle;import Android.app.activity;import Android.view.menu;import Android.view.view;import Android.widget.adapterview;import Android.widget.adapterview.onitemclicklistener;import Android.widget.arrayadapter;import Android.widget.listadapter;import Android.widget.listview;import android.widget.Toast; Public classMainactivity extends Activity {//name SpaceString namespace="http://tempuri.org/"; //Calling MethodsString methodname="Selectstuall";//webservice the method name exists String EndPoint="http://10.0.2.2:8011/WebService.asmx?wsdl";//local test complete link String soapaction="Http://tempuri.org/selectStuAll";//Namespaces and calling method namesPrivateListView ListView; PrivateListAdapter Adapter; protected voidonCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview (R.layout.activity_main); ListView=(ListView) Findviewbyid (R.ID.LISTVIEW1); Adapter=NewArrayadapter<string> (mainactivity. This, Android. R.layout.simple_list_item_1,getsource ()); Listview.setadapter (adapter); Listview.setonitemclicklistener (NewOnitemclicklistener () {@Override Public voidOnitemclick (adapterview<?> arg0, View arg1,intArg2,LongArg3) { //TODO Auto-generated method stubsToast.maketext (mainactivity. This,">>"+adapter.getitem (ARG2),1). Show (); } }); } PublicList<string>GetSource () {List<String> list=NewArraylist<string>(); //instantiating a Soapobject objectSoapobject request=NewSoapobject (NameSpace, methodName); //The second step: If the method has parameters, set the calling method parameter /*Request.addproperty ("username", "1"); Request.addproperty ("Password", "2"); Request.addproperty ("Tel", "3");*/ //get the serialized envelopeSoapserializationenvelope envelope=NewSoapserializationenvelope (SOAPENVELOPE.VER12); Envelope.bodyout=request; Envelope.dotnet=true; Httptransportse Transport=NewHttptransportse (EndPoint); Try{Transport.call (soapaction, envelope); } Catch(IOException e) {//TODO Auto-generated catch blockE.printstacktrace (); } Catch(xmlpullparserexception e) {//TODO Auto-generated catch blockE.printstacktrace (); }Soapobject result =NULL; Try{result=(Soapobject) envelope.getresponse (); } Catch(SoapFault e) {//TODO Auto-generated catch blockE.printstacktrace (); } intCount=Result.getpropertycount (); for(intindex=1; index<count;index=index+3) {List.add (Result.getproperty (index). toString ()); } returnlist; }}
This will be done, if there is a problem with this method, in the following comments, I will help you solve.
Android Connection WebService (using the jar package provided by Google)