Android AsyncTask SOAP Webservice Call Code:
private static String SOAPACTION = "urn:sap-com:document:sap:rfc:functions/ZTEST_FM";
private static String METHODNAME = "ZTEST_FM";
private static String NAMESPACE = "urn:sap-com:document:sap:rfc:functions";
private static String URL ="https://Host:Port/sap/bc/srt/rfc/sap/zws_test_fm1/400/zws_test_fm1/zws_test_fm1";
public class SOAPWebServiceCall extends AsyncTask {
ProgressDialog responseDialog;
@Override
protected void onPreExecute() {
// TODO Auto-generated method stub
responseDialog = ProgressDialog.show(MainActivity.this, "", "Please Wait", true);
super.onPreExecute();
}
@Override
protected String doInBackground(String... params) {
// TODO Auto-generated method stub
SoapObject request1 = new SoapObject(NAMESPACE, METHODNAME);
request1.addProperty("IM_KUNNR", "42");
request1.addProperty("IS_COPYREFERENCE", "");
request1.addProperty("KTOKD", "ZCON");
request1.addProperty("KUNNR", "");
request1.addProperty("BUKRS", "");
request1.addProperty("VKORG", "");
request1.addProperty("VTWEG", "");
request1.addProperty("SPART", "");
request1.addProperty("IS_COPYREFERENCE", "");
String xml = "..."; // contains Email, Password, TokenId etc
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = false;
envelope.implicitTypes = true;
envelope.setOutputSoapObject(request1);
/***************
* Https service means pls uncomment the SSLConnection.allowAllSSL
******************/
SSLConnection.allowAllSSL();
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL, 150000);
androidHttpTransport.debug = true;
androidHttpTransport.setXmlVersionTag("");
SoapObject response = null;
try {
List headerList = new ArrayList();
headerList.add(new HeaderProperty("Authorization",
"Basic " + org.kobjects.base64.Base64.encode("yugeshm:welcome02".getBytes())));
headerList.add(new HeaderProperty("Content-Type", "text/xml"));
headerList.add(new HeaderProperty("Accept", "application/soap+xml"));
androidHttpTransport.call(SOAPACTION, envelope, headerList);
response = (SoapObject) envelope.bodyIn;
resultString_LeaveDetails = androidHttpTransport.responseDump;
} catch (Exception e) {
e.printStackTrace();
}
return response.toString();
}
@Override
protected void onPostExecute(String result) {
// TODO Auto-generated method stub
responseDialog.dismiss();
Log.w("Output result: ", result);
}
}