This tutorial outlines difference (comparison) between WSClient++ and KSoap tool to connect web services.
Sample Web Service
Lets consider a very simple web service, that will return simple “Hello World” string.
KSoap Web Service Call for Android
- private static 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://localhost/TestWeb/WebService.asmx";
- public object GetResponse() throws Exception
- {
- SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
- 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();
- }
Wow, you can see just to call one method, there is 18 lines of code. Well unfortunately you have to write this manually.
WSClient++ Web Service call for Android
WSClient++ generates source code that does all SOAP parsing/encoding for you on the fly. And the code that you have to use in your project will be as small as below,
- public object GetResponse() throws Exception
- {
- HelloWorldService service = new HelloWorldService();
- service.setBaseUrl("http://localhost");
- return service.HelloWorld();
- }
The total lines of code is now 6, and that too, actual service call is as small as just one line. However, in order to write KSoap call on asynchronous, you have to wrap your code around AsyncTask and write more code, where else with WSClient++ it is very easy to write asynchronous call, which works perfect without any hassle.
- public void GetResponseAsync() throws Exception
- {
- HelloWorldService service = new HelloWorldService();
- service.setBaseUrl("http://localhost");
- service.HelloWorld(
- new service.HelloWorldResponse(
- {
- public void onResult(string s){
- }
- public void onError(Exception ex){
- }
- }
- )
- );
- }
Comparison
WSClient++ | KSoap | |
Automatic Code Generator | YES | NO |
Automatic Type (Class) generation for every Soap Input/Output | YES | NO |
Class with IParcelable Implementation | YES | NO |
On the fly Encoding | YES | NO |
Memory Footprint | Small | Big |
Execution Time on Client | Small | Big |
.NET Service Call Detection | Auto | Manual |
Automatic Asynchronous Call Class Generator | YES | NO |