I was wondering my ksoap2 works well without parameters, but with few parameters, my .net service received null value when my android app is trying to access the .net service.
Below are my codes:
String username = usernameTB.getText().toString();
String password = passwordTB.getText().toString();
String ic = ICTB.getText().toString();
String phone = phoneTB.getText().toString();
String email = emailTB.getText().toString();
SoapObject request = new SoapObject(NAMESPACE,METHOD_NAME);
PropertyInfo name = new PropertyInfo();
name.setName("username");
name.setValue(username);
PropertyInfo pass = new PropertyInfo();
pass.setName("userpassword");
pass.setValue(password);
PropertyInfo uic = new PropertyInfo();
uic.setName("useric");
uic.setValue(ic);
PropertyInfo uphone = new PropertyInfo();
uphone.setName("userphone");
uphone.setValue(phone);
PropertyInfo uemail = new PropertyInfo();
uemail.setName("useremail");
uemail.setValue(email);
request.addProperty(name);
request.addProperty(pass);
request.addProperty(uic);
request.addProperty(uphone);
request.addProperty(uemail);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
try
{
androidHttpTransport.call(SOAP_ACTION, envelope);
}
catch(Exception e)
{
e.printStackTrace();
}
private static String NAMESPACE = "http://tempuri.org";
private static String URL = "http://10.0.2.2:31520/testservie/WebService.asmx";
private static String SOAP_ACTION = "http://tempuri.org/teaRegister";
private static String METHOD_NAME = "teaRegister";
And the service code:
public void teaRegister(String username, String userpassword, String useric, String userphone, String useremail)
{
String conn = ConfigurationManager.ConnectionStrings["SQCon"].ConnectionString;
MySqlConnection con = new MySqlConnection(conn);
con.Open();
String register = "Insert Into teausers VALUES(?name,?pass, ?ic,?phone, ?email)";
MySqlCommand insertcmd = new MySqlCommand(register, con);
insertcmd.Parameters.AddWithValue("?name", username);
insertcmd.Parameters.AddWithValue("?pass", userpassword);
insertcmd.Parameters.AddWithValue("?ic", useric);
insertcmd.Parameters.AddWithValue("?phone", userphone);
insertcmd.Parameters.AddWithValue("?email", useremail);
insertcmd.ExecuteNonQuery();
con.Close();
}
Please help me I'm kind of urgent now.