public class MainActivity extends Activity {
private static final String SOAP_ACTION = "http://wsendpoints.bbrailapps.firstgroup.com/getDestinationStationDashboard";
private static final String METHOD_NAME = "getDestinationStationDashboard";
private static final String NAMESPACE = "http://wsendpoints.bbrailapps.firstgroup.com";
private static final String API_URL = "http://railapps.firstgroup.com/FirstGroupRailApps/services/RailAppsCAWS?wsdl";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
new DownloadSoap().execute();
}
private void doNetwork() {
SoapObject resultRequestSOAP = new SoapObject(NAMESPACE, METHOD_NAME);
PropertyInfo pi1 = new PropertyInfo();
pi1.setName("crsCode");
pi1.setValue("HNH");
pi1.setType(PropertyInfo.STRING_CLASS);
resultRequestSOAP.addProperty(pi1);
SoapSerializationEnvelope envp = new SoapSerializationEnvelope(
SoapEnvelope.VER11);
envp.dotNet = true;
try {
envp.setOutputSoapObject(resultRequestSOAP);
HttpTransportSE androidHttpTransport = new HttpTransportSE(API_URL);
androidHttpTransport.debug = true;
androidHttpTransport.call(SOAP_ACTION, envp);
System.out.println(androidHttpTransport.requestDump);
System.out.println(androidHttpTransport.responseDump);
SoapObject response = (SoapObject) envp.getResponse();
System.out.println("resultsString" + response.toString());
} catch (Exception e) {
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
public class DownloadSoap extends AsyncTask<Void, Void, Void> {
private ProgressDialog pd;
@Override
protected void onPreExecute() {
super.onPreExecute();
pd = new ProgressDialog(MainActivity.this);
pd.setMessage("Fetching Data");
pd.setIndeterminate(true);
pd.setCancelable(false);
pd.show();
}
@Override
protected Void doInBackground(Void... params) {
doNetwork();
return null;
}
@Override
protected void onPostExecute(Void result) {
super.onPostExecute(result);
pd.dismiss();
}
}
}
Its working for me, but it taking so much of time to fetch the data.
I am getting Response like below:-
09-20 12:22:39.974: I/System.out(2421): <?xml version="1.0" encoding="UTF-8"?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><soapenv:Body><getDestinationStationDashboardResponse
xmlns="http://wsendpoints.bbrailapps.firstgroup.com"><getDestinationStationDashboardReturn><RID>201309201377851</RID><alertDetailPopulated>false</alertDetailPopulated>
<alertsId>0</alertsId><alertsSummary xsi:nil="true"/><destExpArrival>08:15</destExpArrival><destSchArrival>08:15</destSchArrival><destinationStation><crsCode>BKJ</crsCode>
<stationName>Beckenham Junction</stationName></destinationStation><expArrival>08:04</expArrival><expDepart>08:04</expDepart><otherAlertPresent>false</otherAlertPresent>
<platformNo>3</platformNo><routeDetailPopulated>false</routeDetailPopulated><routeDetails xsi:nil="true"/><rsID xsi:nil="true"/><schArrival>08:04</schArrival><schDepart>08:04</schDepart>
<serviceAlertPresent>false</serviceAlertPresent><toc>SE</toc><tocName>Southeastern</tocName><trainID>2M20</trainID><trainLastReportedAt xsi:nil="true"/></getDestinationStationDashboardReturn>
<getDestinationStationDashboardReturn><RID>201309201377886</RID><alertDetailPopulated>false</alertDetailPopulated><alertsId>0</alertsId><alertsSummary xsi:nil="true"/>
<destExpArrival>08:30</destExpArrival><destSchArrival>08:30</destSchArrival><destinationStation><crsCode>BKJ</crsCode><stationName>Beckenham Junction</stationName>
</destinationStation><expArrival>08:19</expArrival><expDepart>08:19</expDepart><otherAlertPresent>false</otherAlertPresent><platformNo>3</platformNo>
<routeDetailPopulated>false</routeDetailPopulated><routeDetails xsi:nil="true"/><rsID xsi:nil="true"/><schArrival>08:19</schArrival><schDepart>08:19</schDepart>
<serviceAlertPresent>false</serviceAlertPresent><toc>SE</toc><tocName>Southeastern</tocName><trainID>2M22</trainID><trainLastReportedAt xsi:nil="true"/>
</getDestinationStationDashboardReturn><getDestinationStationDashboardReturn><RID>201309201377085</RID><alertDetailPopulated>false</alertDetailPopulated>
<alertsId>0</alertsId><alertsSummary xsi:nil="true"/><destExpArrival>09:38</destExpArrival><destSchArrival>09:38</destSchArrival><destinationStation>
<crsCode>BDM</crsCode><stationName>Bedford</stationName></destinationStation><expArrival>08:12</expArrival><expDepart>08:13</expDepart>
<otherAlertPresent>false</otherAlertPresent><platformNo>2</platformNo><routeDetailPopulated>false</routeDetailPopulated><routeDetails xsi:nil="true"/>
<rsID xsi:nil="true"/><schArrival>08:12</schArrival><schDepart>08:13</schDepart><serviceAlertPresent>false</serviceAlertPresent>
<toc>SE</toc><tocName>Southeastern</tocName><trainID>1G65</trainID><trainLastReportedAt xsi:nil="true"/></getDestinationStationDashboardReturn>
<getDestinationStationDashboardReturn><RID>201309201386846</RID><alertDetailPopulated>false</alertDetailPopulated><alertsId>0</alertsId>
<alertsSummary xsi:nil="true"/><destExpArrival>10:08</destExpArrival><destSchArrival>10:08</destSchArrival><destinationStation>
<crsCode>BDM</crsCode><stationName>Bedford</stationName></destinationStation><expArrival>08:41</expArrival>
<expDepart>08:41</expDepart><otherAlertPresent>false</otherAlertPresent><platformNo>1</platformNo>
<routeDetailPopulated>false</routeDetailPopulated><routeDetails xsi:nil="true"/><rsID xsi:nil="true"/>
<schArrival>08:41</schArrival><schDepart>08:41</schDepart><serviceAlertPresent>false</serviceAlertPresent>
<toc>FC</toc><tocName>First Capital Connect</tocName><trainID>2W70</trainID><trainLastReportedAt>Train last reported at : Haywards Heath</trainLastReportedAt>
</getDestinationStationDashboardReturn><getDestinationStationDashboardReturn><RID>201309201377851</RID><alertDetailPopulated>false</alertDetailPopulated>
<alertsId>0</alertsId><alertsSummary xsi:nil="true"/><destExpArrival>08:24</destExpArrival><destSchArrival>08:24</destSchArrival><destinationStation>
<crsCode>BKL</crsCode><stationName>Bickley</stationName></destinationStation><expArrival>08:04</expArrival><expDepart>08:04</exp
Hope this will help you.
The simplest way to parse Soap Response using the help of this class Create a class name SoapResponseParser
public class SoapResponseParser {
public static void parseBusinessObject(String input, Object output)
throws NumberFormatException, IllegalArgumentException,
IllegalAccessException, InstantiationException {
@SuppressWarnings("rawtypes")
Class theClass = output.getClass();
Field[] fields = theClass.getDeclaredFields();
for (int i = 0; i < fields.length; i++) {
Type type = fields[i].getType();
fields[i].setAccessible(true);
// detect String
if (fields[i].getType().equals(String.class)) {
String tag = fields[i].getName() + "=";
if (input.contains(tag)) {
String strValue = input.substring(
input.indexOf(tag) + tag.length(),
input.indexOf(";", input.indexOf(tag)));
if (strValue.length() != 0) {
if (strValue.contains("anyType")) {
fields[i].set(output, "-");
} else
fields[i].set(output, strValue);
}
}
}
// detect int or Integer
if (type.equals(Integer.TYPE) || type.equals(Integer.class)) {
String tag = fields[i].getName() + "=";
if (input.contains(tag)) {
String strValue = input.substring(
input.indexOf(tag) + tag.length(),
input.indexOf(";", input.indexOf(tag)));
if (strValue.length() != 0) {
fields[i].setInt(output, Integer.valueOf(strValue));
}
}
}
// detect float or Float
if (type.equals(Float.TYPE) || type.equals(Float.class)) {
String tag = fields[i].getName() + "=";
if (input.contains(tag)) {
String strValue = input.substring(
input.indexOf(tag) + tag.length(),
input.indexOf(";", input.indexOf(tag)));
if (strValue.length() != 0) {
fields[i].setFloat(output, Float.valueOf(strValue));
}
}
}
// detect double or Double
if (type.equals(Double.TYPE) || type.equals(Double.class)) {
String tag = fields[i].getName() + "=";
if (input.contains(tag)) {
String strValue = input.substring(
input.indexOf(tag) + tag.length(),
input.indexOf(";", input.indexOf(tag)));
if (strValue.length() != 0) {
fields[i].setDouble(output, Double.valueOf(strValue));
}
}
}
}
}
}
Edited doNetwork() method
private void doNetwork() {
SoapObject resultRequestSOAP = new SoapObject(NAMESPACE, METHOD_NAME);
PropertyInfo pi1 = new PropertyInfo();
pi1.setName("crsCode");
pi1.setValue("HNH");
pi1.setType(PropertyInfo.STRING_CLASS);
resultRequestSOAP.addProperty(pi1);
SoapSerializationEnvelope envp = new SoapSerializationEnvelope(
SoapEnvelope.VER11);
envp.dotNet = true;
try {
envp.setOutputSoapObject(resultRequestSOAP);
HttpTransportSE androidHttpTransport = new HttpTransportSE(API_URL);
androidHttpTransport.debug = true;
androidHttpTransport.call(SOAP_ACTION, envp);
System.out.println(androidHttpTransport.requestDump);
System.out.println(androidHttpTransport.responseDump);
SoapObject response = (SoapObject) envp.getResponse();
GetDestinationStationDashboardReturn destination= new GetDestinationStationDashboardReturn();
System.out.println("resultsString" + response.toString());
SoapResponseParser.parseBusinessObject(response.toString(),
destination);
System.out.println(destination.getRID()+" "+destination.getAlertDetailPopulated()+" "+destination.getAlertsId());
} catch (Exception e) {
}
}
Now i explained how to parse, now its up to you how to achieve your requirement. Happy Coding.
Create a Class GetDestinationStationDashboardReturn
public class GetDestinationStationDashboardReturn {
private String RID;
private String alertDetailPopulated;
private String alertsId;
private String destExpArrival;
private String destSchArrival;
public String getRID() {
return RID;
}
public void setRID(String rID) {
RID = rID;
}
public String getAlertDetailPopulated() {
return alertDetailPopulated;
}
public void setAlertDetailPopulated(String alertDetailPopulated) {
this.alertDetailPopulated = alertDetailPopulated;
}
public String getAlertsId() {
return alertsId;
}
public void setAlertsId(String alertsId) {
this.alertsId = alertsId;
}
public String getDestExpArrival() {
return destExpArrival;
}
public void setDestExpArrival(String destExpArrival) {
this.destExpArrival = destExpArrival;
}
public String getDestSchArrival() {
return destSchArrival;
}
public void setDestSchArrival(String destSchArrival) {
this.destSchArrival = destSchArrival;
}
}