consume web service using android.

Quickly share your Android Code Snippets here...

consume web service using android.

Postby roysamuel » Wed Sep 29, 2010 3:57 am

Obtain the "ksoap2-android" jar file from : link text [http://ksoap2-android.googlecode.com/files/ksoap2-android-assembly-2.4-jar-with-dependencies.jar]

Add this as an "Add External JAR" in your eclipse project.

Then use AndroidHttpTransport object as shown in the code snippet below :

Code: Select all
        String SOAP_ACTION = "http://tempuri.org/Add";
        String METHOD_NAME = "Add";
        String NAMESPACE = "http://tempuri.org/";
        String URL = "http://www.html2xml.nl/Services/Calculator/Version1/Calculator.asmx";
try
        {
            SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
            request.addProperty("a", "15");
            request.addProperty("b", "20");
            SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
            envelope.dotNet=true;
            envelope.setOutputSoapObject(request);
            AndroidHttpTransport androidHttpTransport = new AndroidHttpTransport(URL);
            androidHttpTransport.call(SOAP_ACTION, envelope);
            SoapPrimitive result = (SoapPrimitive)envelope.getResponse();
            returnMessage = result.toString();
        }
        catch (SoapFault sf){
            returnMessage = "FAULT:\n";
            String faultString = "Code: " + sf.faultcode + "\nString: " +
            sf.faultstring;
            Log.d(TAG , "fault : " + faultString);
            returnMessage += faultString;
        }
        catch( Exception e )
        {
            Log.d(TAG , "exception e = "+ e.getMessage());
            returnMessage = "Call Exception:" + e.toString();
        }


    return returnMessage;

Truth Liberates <>< <>< <><
Roy Samuel.
User avatar
roysamuel
Freshman
Freshman
 
Posts: 6
Joined: Tue Apr 20, 2010 8:20 am

Top

Return to Code Snippets for Android

Who is online

Users browsing this forum: No registered users and 2 guests