1

Visual Studio を使用して Web サービスを作成し、テストしたところ、正常に動作しました。Eclipse から Web メソッドを呼び出そうとしています。エラーは発生しませんが、問題は何も起こりません。ユーザーから取得した値をデータベースに挿入することになっています。以下に Java クラスと Web メソッドを示します。私は何を間違っていますか?助けてください

////値を渡す Web メソッドを呼び出す Java クラス/////

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;
        }
      }
    });
}

}

///Visual Studio の 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;
}
4

1 に答える 1

0

誰かのおかげで、何が間違っていたのかわかりました。

1)私は使用しました:

AndroidHttpTransport androidHttpTransport = new AndroidHttpTransport(SOAP_ADDRESS); 

代わりに、次のようにする必要があります。

HttpTransportSE httptransport = new HttpTransportSE(SOAP_ADDRESS);

2)私は使用しました:

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

代わりに、次のようにする必要があります。

request.addProperty("fname", String.valueOf(firstname));

他のテキストフィールドについても

于 2012-07-02T08:02:57.200 に答える