title: I am trying to create an app in android to insert data into sql server through a web service.
body: <p>Hi guys I am new in android here m trying to save some data in sql server from android through a webservice.
  I have created a sample app in android and a webservice.
  I am getting an exception but i am not able to resolve the exception in java.
  Here is the code which i am using.</p>
  
  <p>This is the webservice which i am using.
  Its working fine.</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Web;
  using System.Web.Services;
  using System.Data.SqlClient;
  using System.Runtime.Serialization;
  
  namespace Common.Services
  {
      /// &lt;summary&gt;
      /// Summary description for AndroidService
      /// &lt;/summary&gt;
      [WebService(Namespace = "http://tempuri.org/")]
      [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
      [System.ComponentModel.ToolboxItem(false)]
      // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
      // [System.Web.Script.Services.ScriptService]
      public class AndroidService : System.Web.Services.WebService
      {
  
          [WebMethod]
          public string InsertUserDetails(UserDetails userInfo)
          {
              string strMessage;
              SqlConnection con = new SqlConnection("Data Source=106.205.11.220;Initial Catalog=mydb;User ID=usernm;Password=passwd");
              con.Open();
              SqlCommand cmd = new SqlCommand("insert INTO android_Sample (SampleName,SampleValue,AddDate) VALUES(@Name,@Value,dateadd(minute,330,getdate()))", con);
              cmd.Parameters.AddWithValue("@Name", userInfo.UserName);
              cmd.Parameters.AddWithValue("@Value", userInfo.UserAge);
              int result = cmd.ExecuteNonQuery();
              if (result == 1)
              {
                  strMessage = userInfo.UserName + " Details inserted successfully";
              }
              else
              {
                  strMessage = userInfo.UserName + " Details not inserted successfully";
              }
              con.Close();
              return strMessage;
          }
  
          public class UserDetails
          {
              string name = string.Empty;
              string age = string.Empty;
  
              [DataMember]
              public string UserName
              {
                  get { return name; }
                  set { name = value; }
              }
  
              [DataMember]
              public string UserAge
              {
                  get { return age; }
                  set { age = value; }
              }
  
          }
      }
  }
  </code></pre>
  
  <p>This is the MainActivity.java file.
  here i am getting an exception</p>
  
  <pre><code>    package tecs.example.wsd;
  
      import android.os.Bundle;
      import android.app.Activity;
      import android.view.Menu;
      import org.ksoap2.SoapEnvelope;
      import org.ksoap2.SoapFault;
      import org.ksoap2.serialization.PropertyInfo;
      import org.ksoap2.serialization.SoapObject;
      import org.ksoap2.serialization.SoapSerializationEnvelope;
      import org.ksoap2.transport.HttpTransportSE;
      import android.view.View;
      import android.widget.Button;
      import android.widget.EditText;
      import android.widget.Toast;
  
      public class MainActivity extends Activity 
      {
           /** Called when the activity is first created. */
              private static String SOAP_ACTION = "http://tempuri.org/InsertUserDetails";
              private static String NAMESPACE = "http://tempuri.org/";
              private static String METHOD_NAME = "InsertUserDetails";
  
              private static String URL = "http://192.168.1.137/common.ui/Services/AndroidService.asmx";
  
              Button btnSend;
              EditText txtName, txtVal;
  
          @Override
          protected void onCreate(Bundle savedInstanceState) {
              super.onCreate(savedInstanceState);
              setContentView(R.layout.activity_main);
              btnSend=(Button)findViewById(R.id.btnSend);
              txtName=(EditText)findViewById(R.id.txtText);
              txtVal=(EditText)findViewById(R.id.txtValue);
  
              btnSend.setOnClickListener(new View.OnClickListener() 
              {
  
                  @Override
                  public void onClick(View v) 
                  {
                      //Initialize soap request + add parameters
                      SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);        
                      PropertyInfo pi=new PropertyInfo();
                      pi.setName("UserName");
                      pi.setValue(txtName.getText().toString());
                      pi.setType(String.class);
                      request.addProperty(pi);
                      pi=new PropertyInfo();
                      pi.setName("UserAge");
                      pi.setValue(txtVal.getText().toString());
                      pi.setType(String.class);
                      request.addProperty(pi);
                      //Declare the version of the SOAP request
                      SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
  
                      envelope.setOutputSoapObject(request);
                      envelope.dotNet = true;
  
                      try {
  
                          HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
  
                          //this is the actual part that will call the webservice
                          androidHttpTransport.call(SOAP_ACTION, envelope);
  // Get the SoapResult from the envelope body.
                              SoapObject result = (SoapObject)envelope.bodyIn;
  
  
  
                              if(result != null)
                              {
  
  
                                  Toast.makeText(getBaseContext(), result.getProperty(0).toString(), Toast.LENGTH_SHORT).show();
                                  txtName.setText("");
                                  txtVal.setText("");
  
                              }
                              else
                              {
                                  Toast.makeText(getApplicationContext(), "No Response",Toast.LENGTH_LONG).show();
                              }
                          } catch (Exception e) {
                              e.printStackTrace();
                          }
                      }
                  });
              }
  
              @Override
              public boolean onCreateOptionsMenu(Menu menu) {
                  // Inflate the menu; this adds items to the action bar if it is present.
                  getMenuInflater().inflate(R.menu.main, menu);
                  return true;
              }
  
          }
  </code></pre>
  
  <p>I am getting this exception</p>
  
  <blockquote>
    <p>java.lang.ClassCastException: org.ksoap2.SoapFault</p>
  </blockquote>
  
  <p>on this line</p>
  
  <pre><code>// Get the SoapResult from the envelope body.
  SoapObject result = (SoapObject)envelope.bodyIn;
  </code></pre>
  
  <p>This is my Manifest file code</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="tecs.example.wsd"
      android:versionCode="1"
      android:versionName="1.0" &gt;
  
      &lt;uses-sdk
          android:minSdkVersion="10"
          android:targetSdkVersion="17" /&gt;
      &lt;uses-permission android:name="android.permission.INTERNET" /&gt;
      &lt;application
          android:allowBackup="true"
          android:icon="@drawable/ic_launcher"
          android:label="@string/app_name"
          android:theme="@style/AppTheme" &gt;
          &lt;activity
              android:name="tecs.example.wsd.MainActivity"
              android:label="@string/app_name" &gt;
              &lt;intent-filter&gt;
                  &lt;action android:name="android.intent.action.MAIN" /&gt;
  
                  &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
              &lt;/intent-filter&gt;
          &lt;/activity&gt;
      &lt;/application&gt;
  
  &lt;/manifest&gt;
  </code></pre>
  
  <p>This is my Layout file</p>
  
  <pre><code>&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"
      android:orientation="vertical" &gt;
  
  
  
      &lt;EditText
          android:id="@+id/txtText"
          android:layout_width="fill_parent"
          android:layout_height="150dp"
          android:gravity="top"
          android:inputType="textMultiLine"
          android:hint="@string/Text_Hint" /&gt;
  
      &lt;EditText 
          android:id="@+id/txtValue"
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:inputType="number"
          android:hint="@string/Value_Hint" /&gt;
  
      &lt;Button
          android:id="@+id/btnSend"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_gravity="center_horizontal"
          android:text="@string/btnSend_text" /&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>this is my string values file</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;resources&gt;
  
      &lt;string name="app_name"&gt;WSD&lt;/string&gt;
      &lt;string name="action_settings"&gt;Settings&lt;/string&gt;
      &lt;string name="hello_world"&gt;Hello world!&lt;/string&gt;
      &lt;string name="Text_Hint"&gt;Enter Text&lt;/string&gt;
      &lt;string name="Value_Hint"&gt;Enter Value&lt;/string&gt;
      &lt;string name="btnSend_text"&gt;Send&lt;/string&gt;
  &lt;/resources&gt;
  </code></pre>
  
  <p>Can anyone help me with this.
  what is wrong? 
  which is the right method for it? 
  How to resolve this error?</p>