Android 使用KSOAP2从eclipse调用web方法

Android 使用KSOAP2从eclipse调用web方法,android,eclipse,web-services,ksoap2,Android,Eclipse,Web Services,Ksoap2,我使用visualstudio创建了一个web服务,并对其进行了测试,效果很好。我正在尝试从eclipse调用一个web方法。我没有发现任何错误,但问题是什么也没发生。它应该将从用户获取的值插入数据库。我在下面给出了java类和web方法。我做错了什么?请帮忙 ////Java类调用传入值的web方法///// public class Registration extends Activity{ private static final String SOAP_ACTION = "http:/

我使用visualstudio创建了一个web服务,并对其进行了测试,效果很好。我正在尝试从eclipse调用一个web方法。我没有发现任何错误,但问题是什么也没发生。它应该将从用户获取的值插入数据库。我在下面给出了java类和web方法。我做错了什么?请帮忙

////Java类调用传入值的web方法/////

public class Registration extends Activity{
private static final String SOAP_ACTION = "http://tempuri.org/register";
private static final String OPERATION_NAME = "register";
private static final String WSDL_TARGET_NAMESPACE = "http://tempuri.org/";
private static final String SOAP_ADDRESS = "http://10.0.2.2:54714/WebSite1/Service.asmx";

Button sqlRegister;
EditText  sqlFirstName,sqlLastName,sqlEmail,sqlMobileNumber,sqlCurrentLocation,sqlUsername,sqlPassword;

@Override
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.registration);
sqlFirstName = (EditText) findViewById(R.id.etFname);
sqlLastName = (EditText) findViewById(R.id.etLname);
sqlEmail = (EditText) findViewById(R.id.etEmail);
sqlMobileNumber = (EditText) findViewById(R.id.etPhone);
sqlCurrentLocation = (EditText) findViewById(R.id.etCurrentLoc);

sqlUsername = (EditText) findViewById(R.id.etUsername);
sqlPassword = (EditText) findViewById(R.id.etPwd);

sqlRegister = (Button) findViewById(R.id.bRegister);
sqlRegister.setOnClickListener(new View.OnClickListener() {

    public void onClick(View v) {
        switch (v.getId()){
        case R.id.bRegister:
             try{
                String firstname = sqlFirstName.getText().toString();
                String lastname = sqlLastName.getText().toString();
                String emailadd = sqlEmail.getText().toString();
                String number = sqlMobileNumber.getText().toString();
                String loc = sqlCurrentLocation.getText().toString();
                String uname = sqlUsername.getText().toString();
                String pwd = sqlPassword.getText().toString();

                SoapObject Request = new SoapObject(WSDL_TARGET_NAMESPACE,OPERATION_NAME);

                PropertyInfo pi = new PropertyInfo();
                pi.setName("fname");
                pi.setValue(firstname);
                pi.setType(int.class);
                Request.addProperty(pi);

                PropertyInfo pi2 = new PropertyInfo();
                pi2.setName("lname");
                pi2.setValue(lastname);
                pi2.setType(int.class);
                Request.addProperty(pi2);

                PropertyInfo pi3 = new PropertyInfo();
                pi2.setName("email");
                pi2.setValue(emailadd);
                pi2.setType(int.class);
                Request.addProperty(pi3);

                PropertyInfo pi4 = new PropertyInfo();
                pi2.setName("num");
                pi2.setValue(number);
                pi2.setType(int.class);
                Request.addProperty(pi4);

                PropertyInfo pi5 = new PropertyInfo();
                pi2.setName("locID");
                pi2.setValue(loc);
                pi2.setType(int.class);
                Request.addProperty(pi5);

                PropertyInfo pi6 = new PropertyInfo();
                pi2.setName("username");
                pi2.setValue(uname);
                pi2.setType(int.class);
                Request.addProperty(pi6);

                PropertyInfo pi7 = new PropertyInfo();
                pi2.setName("password");
                pi2.setValue(pwd);
                pi2.setType(int.class);
                Request.addProperty(pi7);

                SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
                envelope.dotNet = true;
                envelope.setOutputSoapObject(Request);
                AndroidHttpTransport androidHttpTransport = new AndroidHttpTransport(SOAP_ADDRESS);
                try
                {
                    androidHttpTransport.call(SOAP_ACTION, envelope);
                    SoapObject response = (SoapObject)envelope.getResponse();
                    int result =  Integer.parseInt(response.getProperty(0).toString());
                    if(result ==1){
                        Toast.makeText(Registration.this, "You have been registered Successfully", Toast.LENGTH_LONG).show();
                    }
                    else
                    {
                        Toast.makeText(Registration.this, "Try Again", Toast.LENGTH_LONG).show();
                    }
                }
                catch(Exception e)
                {
                   e.printStackTrace();
                }
            break;
        }
      }
    });
}
}

///visualstudio中的Web方法////

    [WebMethod]
    public int register(string fname, string lname, string email, string num, int locID,string username,string password)
{
    SqlConnection conn;
    conn = ConnectionManager.GetConnection();
    conn.Open();
    string cmdregister = "INSERT into [User] values(@fname,@lname,@email,@num,@locID)";
    SqlCommand sqlCommand = new SqlCommand(cmdregister, conn);
    sqlCommand.CommandType = CommandType.Text;

    sqlCommand.Parameters.Add("@fname", SqlDbType.Text).Value = fname;
    sqlCommand.Parameters.Add("@lname", SqlDbType.Text).Value = lname;
    sqlCommand.Parameters.Add("@email", SqlDbType.Text).Value = email;
    sqlCommand.Parameters.Add("@num", SqlDbType.Text).Value = num;
    sqlCommand.Parameters.Add("@locID", SqlDbType.Int).Value = locID;
    sqlCommand.ExecuteNonQuery();

    string cmdlogin = "INSERT into [Login] values(@username,@id,@password)";
    SqlCommand sqllogin = new SqlCommand(cmdlogin, conn);
    sqllogin.CommandType = CommandType.Text;

    sqllogin.Parameters.Add("@username", SqlDbType.Text).Value = username;
    sqllogin.Parameters.Add("@password", SqlDbType.Text).Value = password;
    sqllogin.ExecuteNonQuery();
    conn.Close();
    return 1;
}

多亏有人,我才发现问题所在

1) 我使用了:

AndroidHttpTransport androidHttpTransport = new AndroidHttpTransport(SOAP_ADDRESS); 
            PropertyInfo pi = new PropertyInfo();
            pi.setName("fname");
            pi.setValue(firstname);
            pi.setType(int.class);
            Request.addProperty(pi);
相反,它应该是:

HttpTransportSE httptransport = new HttpTransportSE(SOAP_ADDRESS);
request.addProperty("fname", String.valueOf(firstname));
2) 我使用了:

AndroidHttpTransport androidHttpTransport = new AndroidHttpTransport(SOAP_ADDRESS); 
            PropertyInfo pi = new PropertyInfo();
            pi.setName("fname");
            pi.setValue(firstname);
            pi.setType(int.class);
            Request.addProperty(pi);
相反,它应该是:

HttpTransportSE httptransport = new HttpTransportSE(SOAP_ADDRESS);
request.addProperty("fname", String.valueOf(firstname));
对于其他文本字段也是如此