2

KSOAP を使用して Web サービスを呼び出しています。Web メソッドは完全に機能しており、文字列を「無効」または「有効」として返します。テキストフィールドから取得したユーザー名とパスワードを渡して、有効か無効かを応答しようとしています。エラーは発生しません。log cat に出力されるものと出力されないものを示すコードにコメントしました。Web メソッドから応答を取得する方法に問題があります。私は何を間違っていますか?助けてください

 public class Login extends Activity{

private static final String SOAP_ACTION = "http://tempuri.org/checkLogin";
private static final String OPERATION_NAME = "checkLogin";
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";
public static final String PREFS_NAME = "MyPrefsFile";
private static final String PREF_USERNAME = "username";
private static final String PREF_PASSWORD = "password";
Button sqllogin;
EditText sqlusername, sqlpassword;
TextView tvData1;
CheckBox cb;

 @Override
    protected void onCreate(Bundle savedInstanceState){
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    sqlusername = (EditText) findViewById(R.id.etuname1);
    sqlpassword = (EditText) findViewById(R.id.etpass);
    tvData1 = (TextView)findViewById(R.id.textView1); 
    sqllogin = (Button) findViewById(R.id.bLogin);
    cb = (CheckBox) findViewById(R.id.cbrememberme);


    sqllogin.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            switch (v.getId()){
            case R.id.bLogin:
                new LongOperation().execute("");
            break;
          } 
        }
    });
}

 private class LongOperation extends AsyncTask<String, Void, String> {

        @Override
        protected String doInBackground(String... params) {
            String username = sqlusername.getText().toString();
            String password = sqlpassword.getText().toString();

            SoapObject Request = new SoapObject(WSDL_TARGET_NAMESPACE,OPERATION_NAME);
            Request.addProperty("uname", String.valueOf(username));
            Request.addProperty("pwd", String.valueOf(password));

            SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
            envelope.dotNet = true;
            envelope.setOutputSoapObject(Request);
            HttpTransportSE httpTransport  = new HttpTransportSE(SOAP_ADDRESS);
                    Log.d("work","work");//Only this Log message is displayed in log cat

                   try  {                    
                         httpTransport.call(SOAP_ACTION, envelope);                       
                         Object response = envelope.getResponse();
                         String result =  response.toString();
                         Log.d("res",result);//This is not displayed in log cat

                    if(result.equals("valid"))
                        {
                        Log.d("yes","yes");//This is not displayed in log cat
                        return "valid";
                        }
                    else if(result.equals("invalid"))
                        {
                        Log.d("no","no");//This is not displayed in log cat
                        return "invalid";
                        }
                    }
                   catch(Exception e){
                    e.printStackTrace();                           
                    }
                   return null;
        }

 @Override
 protected void onPostExecute(String result) {
    Log.d("tag","onpost");//This is not displayed in log cat
    if(result!=null)
    {
        if(result.equals("valid"))
            {

            tvData1.setText("You have logged in successfully");
            Intent openhomepage = new Intent("com.android.disasterAlertApp.HOME");
            startActivity(openhomepage);
            }
        else if(result.equals("invalid"))
            {
            tvData1.setText("Invalid Username or password");
            }
    }
    else
    {
        Toast.makeText(Login.this, "Somethings wrong", Toast.LENGTH_LONG).show();
}
 }
4

1 に答える 1

2

私は何が間違っていたのかを理解しました

それ以外の

httpTransport.call(SOAP_ACTION, envelope);                       
                     Object response = envelope.getResponse();
                     String result =  response.toString();

私は使用する必要があります

        httptransport.call(SOAP_ACTION, envelope);
        SoapPrimitive resultstring = (SoapPrimitive) soapenvelope
                        .getResponse();
于 2012-07-12T17:13:18.467 に答える