0

我正在使用使用 KSOAP 的 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, sqlView;

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:

                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);
                Request.addProperty("fname", String.valueOf(firstname));
                Request.addProperty("lname", String.valueOf(lastname));
                Request.addProperty("email", String.valueOf(emailadd));
                Request.addProperty("num", String.valueOf(number));
                Request.addProperty("loc", String.valueOf(loc));
                Request.addProperty("username", String.valueOf(uname));
                Request.addProperty("password", String.valueOf(pwd));
                Toast.makeText(Registration.this, "You have been registered Successfully", Toast.LENGTH_LONG).show();

                SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
                envelope.dotNet = true;
                envelope.setOutputSoapObject(Request);
                HttpTransportSE httpTransport  = new HttpTransportSE(SOAP_ADDRESS);
                try
                {
                    httpTransport.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;
        }
           }
        });
    }

}

在此处输入图像描述

4

2 回答 2

2

您收到 Application Not Responding 错误的非常简单的原因:您正在主 (UI) 线程上发出 Web 请求。Android 线程模型有两条规则:1) 不要阻塞主线程超过几秒钟 2) 不要从主线程更新 UI。你违反了这些规则中的第一条。您应该考虑使用AsyncTask来执行更长的操作。

于 2012-07-11T01:41:14.853 回答
1

httpTransport.call(SOAP_ACTION, envelope); 您正在 UI 线程上进行网络调用。您需要执行所有长时间运行的任务,例如通过网络在单独的线程上访问资源。API 提供了一个方便的类调用[AsyncTask][1],可让您轻松完成此操作。

在其最简单的形式中,您将创建一个扩展 AsyncTask 的类,然后将您httpTransport.call(SOAP_ACTION, envelope);移至它的doInBackground方法。

于 2012-07-11T01:43:47.783 回答