• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Call SOAP webservice and get data from server

zalani

Lurker
//calling in java file
private GetAllActivityResponse [] AllActivityList;// above oncreate(Bundle)
ServiceCaller ser = new ServiceCaller();// written in oncreate(Bundle)
AllActivityList = ser.getAllActivityList();// written in oncreate(Bundle)


//================
//method written in ServiceCaller.java file
//===============================

private static final String SOAP_ACTION = "http://tempuri.org/";
private static final String NAMESPACE = "http://tempuri.org/";
private static final String URL = "http://79.143.179.201/iphoneservice.asmx";
private boolean isResultVector = false;
int t;


public GetAllActivityResponse [] getAllActivityList()
{
final String functionName = "GetAllActivities";
SoapObject request = new SoapObject(NAMESPACE, functionName);
GetAllActivityResponse [] getactivityList = null;
try{
PropertyInfo p1;
p1=new PropertyInfo();

p1.setName("strlangueid");
p1.setValue(DataContainer.langueType.toString());


request.addProperty(p1);


SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.setOutputSoapObject(request);
// It seems that it is a .NET Web service because it doesn't work without next line
envelope.dotNet = true;


Marshal dateMarshal = new MarshalDate();
dateMarshal.register(envelope);
// For float marshaling
Marshal floatMarshal = new MarshalFloat();
floatMarshal.register(envelope);
SoapObject response = (SoapObject)this.call(SOAP_ACTION + functionName, envelope);
SoapObject s = (SoapObject) response.getProperty("diffgram");
SoapObject c =(SoapObject)s.getProperty(0);
getactivityList = new GetAllActivityResponse[c.getPropertyCount()];

for( t = 0; t<c.getPropertyCount();t++)
{
getactivityList[t] = new GetAllActivityResponse((SoapObject)c.getProperty(t));
}

}catch (Exception e)
{
e.getMessage();
}


protected Object call(String soapAction, SoapSerializationEnvelope envelope) {
Object result = null;

final HttpTransportSE transportSE = new HttpTransportSE(URL);

transportSE.debug = false;
try{
// call and Parse Result.
try {
transportSE.call(soapAction, envelope);
if (!isResultVector) {
result = envelope.getResponse();
} else {
result = envelope.bodyIn;
}
} catch (final IOException e) {

e.printStackTrace();
} catch (final XmlPullParserException e) {

e.printStackTrace();
} catch (final Exception e) {

e.printStackTrace();
}
}catch(Exception er){
er.printStackTrace();
}
return result;
}


//---------------------------------------------------
//new javafile GetAllActivityResponse.java
//---------------------------------------------



import org.ksoap2.serialization.SoapObject;

public class GetAllActivityResponse{

private int classificationid;
private String classification_nom;
private int classification_groupe_id;

GetAllActivityResponse(SoapObject sopobj) {
this.classificationid = Integer.parseInt(sopobj.getProperty("classificationid").toString());
this.classification_nom = sopobj.getProperty("classification_nom").toString();
this.classification_groupe_id = Integer.parseInt(sopobj.getProperty("classification_groupe_id").toString());
}

public int getClassificationid() {
return classificationid;
}
public void setClassificationid(int classificationid) {
this.classificationid = classificationid;
}
public String getClassification_nom() {
return classification_nom;
}
public void setClassification_nom(String classificationNom) {
classification_nom = classificationNom;
}
public int getclassification_groupe_id() {
return classification_groupe_id;
}
public void setclassification_groupe_id(int classification_groupe_id) {
this.classification_groupe_id = classification_groupe_id;
}
}

--------------------------------------------
 
Back
Top Bottom