April 18, 2012

How to call webservice from Android Application (app) using SOAP (ksoap2)

How to call webservice from Android Application (app) using SOAP (ksoap2):
Following is the code snippet through which we can call web service from Android apps using soap with ksoap2 api:
 SoapObject request = new SoapObject(nameSpace, methodName);    
            System.out.println("1");
            String result = "";
            request.addProperty("userName", userName);
            request.addProperty("password", password);
           
            SoapSerializationEnvelope envelope =
                new SoapSerializationEnvelope(SoapEnvelope.VER11);

            envelope.setOutputSoapObject(request);
            HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);

            try {
                androidHttpTransport.call(soapAction, envelope);
                result = ""+envelope.getResponse();
                /*SoapPrimitive resultsRequestSOAP = (SoapPrimitive) envelope.getResponse();
                result = resultsRequestSOAP.toString();*/

                //resultsRequestSOAP.
            } catch (Exception e) {
                e.printStackTrace();
            }
           

No comments:

Post a Comment