post data to database using KSoap2
-
I am using Ksoap2 to post my data from android mobile to database.I have a local server api of .Net to send this data .I am using following code to do this protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } public class backMethod extends AsyncTask { private final ProgressDialog dialog = new ProgressDialog(MainActivity.this); @Override protected void onPreExecute() { this.dialog.setMessage("Checking..."); this.dialog.show(); } // @Override // protected void onCancelled(Object result) { // // super.onCancelled(result); // } @Override protected void onPostExecute(Object result) { //Here All your UI part is Done if (result != null) { tv.setTag(result); } else { Toast.makeText(getApplicationContext(), "Result Found is == " + result + "", Toast.LENGTH_LONG).show(); } super.onPostExecute(result); if (this.dialog.isShowing()) { this.dialog.dismiss(); } super.onPostExecute(result); } @Override protected Object doInBackground(String... params) { SoapObject request = new SoapObject(NAMESPACE, OPERATION_NAME); SoapSerializationEnvelope envelope = new SoapSerializationEnvelope( SoapEnvelope.VER11); envelope.dotNet = true; envelope.setOutputSoapObject(request); try { HttpTransportSE androidHttpTransport = new HttpTransportSE(URL); androidHttpTransport.call(SOAP_ACTION, envelope); response = (SoapObject) envelope.getResponse(); //here SoapPrimitive is an important part Toast.makeText(getApplicationContext(), "SEND", Toast.LENGTH_LONG).show(); } catch (Exception e) { e.printStackTrace(); Toast.makeText(getApplicationContext(), "NOT SEND", Toast.LENGTH_LONG).show(); } return response;
-
I am using Ksoap2 to post my data from android mobile to database.I have a local server api of .Net to send this data .I am using following code to do this protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } public class backMethod extends AsyncTask { private final ProgressDialog dialog = new ProgressDialog(MainActivity.this); @Override protected void onPreExecute() { this.dialog.setMessage("Checking..."); this.dialog.show(); } // @Override // protected void onCancelled(Object result) { // // super.onCancelled(result); // } @Override protected void onPostExecute(Object result) { //Here All your UI part is Done if (result != null) { tv.setTag(result); } else { Toast.makeText(getApplicationContext(), "Result Found is == " + result + "", Toast.LENGTH_LONG).show(); } super.onPostExecute(result); if (this.dialog.isShowing()) { this.dialog.dismiss(); } super.onPostExecute(result); } @Override protected Object doInBackground(String... params) { SoapObject request = new SoapObject(NAMESPACE, OPERATION_NAME); SoapSerializationEnvelope envelope = new SoapSerializationEnvelope( SoapEnvelope.VER11); envelope.dotNet = true; envelope.setOutputSoapObject(request); try { HttpTransportSE androidHttpTransport = new HttpTransportSE(URL); androidHttpTransport.call(SOAP_ACTION, envelope); response = (SoapObject) envelope.getResponse(); //here SoapPrimitive is an important part Toast.makeText(getApplicationContext(), "SEND", Toast.LENGTH_LONG).show(); } catch (Exception e) { e.printStackTrace(); Toast.makeText(getApplicationContext(), "NOT SEND", Toast.LENGTH_LONG).show(); } return response;
SoapObject request = new SoapObject(NAMESPACE, SEND_METHOD_NAME);
SoapSerializationEnvelope envelope = getSOAPEnvelope();
envelope.dotNet = true;
envelope.bodyOut = request;// InfoToSend - Web service parameter request.addProperty("InfoToSend", <put your info>); HttpTransportSE androidHttpTransport = new HttpTransportSE(URL, TIMEOUT); androidHttpTransport.debug=true; SoapObject resultsRequestSOAP; try { androidHttpTransport.call(NAMESPACE + SEND\_METHOD\_NAME, envelope); resultsRequestSOAP = (SoapObject) envelope.bodyIn; String result = resultsRequestSOAP.getProperty(0).toString(); if (result.equalsIgnoreCase(RESULT\_OK)) success = true; else WS\_ERROR = result; } catch (java.net.ConnectException ec) { WS\_ERROR = context.getString(R.string.WS\_BAD\_ADDRESS)+": "+URL; } catch (java.net.SocketTimeoutException et) { WS\_ERROR = context.getString(R.string.WS\_TIMEOUT); } catch (java.net.UnknownHostException eh) { WS\_ERROR = context.getString(R.string.WS\_NO\_NETWORK); } catch (Exception ex) { if (ex.toString().contains("FileNotFoundException")) { WS\_ERROR = context.getString(R.string.WS\_NO\_DB); } else { WS\_ERROR = ex.toString(); } }