The kSOAP library is alightweight, and efficient SOAP client library. The library is open source, easy to use, and it can save you from the hassle of coding a custom parser. It is one of the more trusted SOAP libraries currently available and it's frequently updated, which is a good sign for any open source project.
1. Get K-Soap2 library and import to project
- Launch Eclipse and start a new Android Project.
- Download lastest ver sion (jar file) at Google Code.
- Put this jar file in libs folder of your project.
Now, k-soap2 library is ready to use.
And in this tip, we will use W3School webservice example (Temperature converter) at: http://www.w3schools.com/webservices/tempconvert.asmx
And in this tip, we will use W3School webservice example (Temperature converter) at: http://www.w3schools.com/webservices/tempconvert.asmx
2. Defining activity layout
Make a simple xml file for our app:
3. Programmatically coding
(Soap Action = Namespace + Method name).
Define 4 features in ConstantString.java:
Create an AsyncTask to consuming Web service in background thread. In doInBackground(), we create and properties for our SoapObject, create HttpRequest, Envelop, sending request and processing the response... In onPostExcute(), call back to our activity:
Source code for WebServiceCall.java with static method callWSThreadSoapPrimitive() used in doInbackground() of AsyncTask:
Finally, in our activity, call back data from background thread and show to views.
Remember adding Internet permission in AndroidManifest.xml:
<uses-permission android:name="android.permission.INTERNET" />
Some screen shots (click for full size):