2012-07-11 4 views
0

KSOAP를 사용하여 웹 서비스를 사용하여 데이터베이스에 세부 정보를 보내고 있습니다.이 코드는 완벽하게 작동했지만 변경하지 않았습니다. 이제는 작동하지 않습니다. 도와주세요. 웹 서비스를 확인한 다음 작동합니다. 로그 고양이에 대한 세부 정보를 첨부했습니다. 도와주세요 !!!응용 프로그램이 응답하지 않습니다.

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

} 
당신이하지 응답 오류를 응용 프로그램을 얻고있는 이유

enter image description here

답변

2

아주 간단한 이유 : 메인 (UI) 스레드에서 웹 요청을하고 있습니다. Android 스레딩 모델에는 두 가지 규칙이 있습니다. 1) 기본 스레드를 몇 초 동안 차단하지 않습니다. 2) 기본 스레드에서 UI를 업데이트하지 않습니다. 그 규칙들 중 첫 번째 규칙을 위반하고 있습니다. 더 이상 작동하려면 AsyncTask을 사용하십시오.

+0

LuxuryMode에 다음과 같이 덧붙입니다. 기술적으로는 5 초 후에 기술적으로 ANS 스레드를 차단하지 않으려 고합니다. 사용자는 눈치를 챘을 것입니다 =) – FoamyGuy

+0

버튼 안에있는 모든 것을 비동기 작업의 doInbackground 메소드에 넣고 onclick 버튼의 비동기 작업을 호출 할 수 있습니까? –

+0

예, AsyncTask를 확장하는 내부 클래스를 설정 한 다음 onClick에서 실행합니다. AsyncTask의 onPostExecute에서 검색된 데이터로 필요한 작업을 수행하십시오. – LuxuryMode

1

httpTransport.call(SOAP_ACTION, envelope); UI 스레드에서 네트워크 호출을하고 있습니다. 별도의 스레드에서 네트워크를 통해 리소스에 액세스하는 것과 같이 오래 실행되는 모든 작업을 수행해야합니다. API를 통해 편리하게 수행 할 수있는 편리한 클래스 호출 [AsyncTask][1]이 제공됩니다.

가장 간단한 형태로 AsyncTask를 확장하는 클래스를 만든 다음 httpTransport.call(SOAP_ACTION, envelope);doInBackground 메서드로 옮깁니다.

관련 문제