Tuesday, 1 December 2015

example for getting data from web service in android


 String NAMESPACE = "http://tempuri.org/";
String URL="----?wsdl";


public String HelloWorld()
{    
String SOAP_ACTION1 = "http://tempuri.org/HelloWorld";
   String METHOD_NAME1 = "HelloWorld ";
String result_="";  
SoapObject request = new SoapObject(NAMESPACE,METHOD_NAME1);      
     
//request.addProperty("LoginUser",username);  

   SoapSerializationEnvelope envelope =new SoapSerializationEnvelope(SoapEnvelope.VER11);
       envelope.setOutputSoapObject(request);
       envelope.dotNet = true;
      try
      {
            HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
            //this is the actual part that will call the webservice
            androidHttpTransport.call(SOAP_ACTION1, envelope);
         
            // Get the SoapResult from the envelope body.
            SoapObject result = (SoapObject)envelope.bodyIn;
            if(result != null)
            {
           result_=result.getProperty(0).toString().trim();
            }
            else
            {
                result_="no data found";
            }
      } catch (Exception e) {
            e.printStackTrace();
      }
return result_;
}  

No comments:

Post a Comment