Solutionext

KSOAP 2

“KSOAP is a SOAP web service client library for constrained java environment such as Applet or J2ME applications”.

It also provides a light weight and efficient SOAP library for android platform (ksoap2-android) with some more features and enhancements. They take quick actions to fix the bugs and takes in the contribution and release updates regularly.   Ksoap2-android is licensed under MIT therefore it can be used in commercial projects as well.

Why KSOAP 2 ?

Android software development kit is comparatively new and still provides great offers and support for many features and tasks. But so far in all the releases of android it has not made any explicit effort to support SOAP.

 

How to use it?

In order to use KSOAP in android project we need to download its jar files and add it as an external library. To add third party jar files in  eclipse project we need to do following steps:

  • In package explorer of android application, write click on the project and go to the properties.
  • Select build path and go to the libraries tab.
  • Now click on the “add jar” button to add Ksoap2-android libraries and enjoy SOAP functionalities in your android application.

Code Sample

 

private String SendLoginData(String ID, String Pwd, View view)
{
SoapObject request = new SoapObject(NAMESPACE, “session_creater”);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
request.addProperty(“myId”, ID);
request.addProperty(“Pass”, Pwd);
AndroidHttpTransport aht = new AndroidHttpTransport(URL);
Object result;
try
{
aht.call(“http://tempuri.org/session_creater”, envelope);
result = (Object)envelope.getResponse();
//storing session ID (Random ID)
UserSession = result.toString();
String err = “Error 110″;
if(UserSession.equals(err))
{
errMsg.setText(“Invalid User Name or Password”);
}
else
{
UserID.setText(“”);
UserPwd.setText(“”);
Intent myIntent = new Intent(view.getContext(), Home.class);
startActivityForResult(myIntent, 0);
}
} catch (Exception ex) {
errMsg.setText(ex.getMessage());
result = “”;
}
return result.toString();
}
Categories: Android, Microsoft, Open Source

Leave a Reply

You must be logged in to post a comment.