Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Mobile Development
  3. Android
  4. post data to database using KSoap2

post data to database using KSoap2

Scheduled Pinned Locked Moved Android
csharpandroiddatabasewcfdesign
2 Posts 2 Posters 12 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    Barun42
    wrote on last edited by
    #1

    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;

    U 1 Reply Last reply
    0
    • B Barun42

      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;

      U Offline
      U Offline
      User 10386129
      wrote on last edited by
      #2

      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();
              }
      	}
      
      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups