Original articles, reproduced please specify the Source: http://WWW.BLOG.CSDN.NET/TANGCHENG_OKto call WebService on Android, you have to need some libraries to support, in the example above, we access webservice through Xfire, but these libraries are not suitable for our Android client. Here is an open source project on Google Code KSOAP2-android,ksoap2-Android provides a lightweight and efficient soap library to access WebService. Download Ksoap2-android-assembly-2.6.0-jar-with-dependencies, and add it to the Android project, in this case just pass a simple string, the general use of WebService will use XML or JSON to share the data, as long as the specific needs, It is possible to parse the Envelope.bodyin data. WebService Service-side construction please refer to "Android Call WebService Server implementation (a)", nothing to say, directly on the code bar<span style= "FONT-SIZE:16PX;" > PackageOrg.winplus.aws; Importjava.io.IOException; ImportOrg.ksoap2.SoapEnvelope; ImportOrg.ksoap2.serialization.SoapObject; ImportOrg.ksoap2.serialization.SoapSerializationEnvelope; ImportOrg.ksoap2.transport.HttpTransportSE; Importorg.xmlpull.v1.XmlPullParserException; Importandroid.app.Activity; ImportAndroid.os.Bundle; ImportAndroid.util.Log; Public classMainactivityextendsActivity {Private Final StaticString TAG = "Mainactivity"; //name Space Private Static FinalString servicenamespace = "Http://192.168.217.1:8080/WebServiceDemo"; Private Static FinalString example = "Example"; //Request URL Private Static FinalString serviceurl = "Http://192.168.217.1:8080/WebServiceDemo/services/HelloWorld"; @Override Public voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate); Setcontentview (R.layout.main); Try{log.e (TAG, Getrequestdata ()); } Catch(IOException e) {e.printstacktrace (); } Catch(xmlpullparserexception e) {e.printstacktrace (); } } /** * * @return * @throwsIOException *@throwsxmlpullparserexception*/ PrivateString Getrequestdata ()throwsIOException, xmlpullparserexception {//instantiate the Soapobject object, specify the namespace of the webservice, and the name of the calling methodSoapobject request =NewSoapobject (Servicenamespace, example); //there is a string argument in the example method, where the "Android client" is passed to exampleRequest.addproperty ("message", "Android Client"); //get the serialized envelopeSoapserializationenvelope envelope; Envelope=NewSoapserializationenvelope (SOAPENVELOPE.VER11); Envelope.bodyout=request; //Android Transfer ObjectHttptransportse transport =NewHttptransportse (serviceurl); Transport.debug=true; //Call WebServiceTransport.call (Servicenamespace +example, envelope); if(Envelope.getresponse ()! =NULL) { returnenvelope.bodyIn.toString (); } return NULL; } } </span>function code is relatively simple, there is a call WebService analytic weather forecast example, interested to see it. SOURCE Download= = "
Android calls WebService's client implementation (II)