Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/344.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 无法在android中检索web方法的响应_Java_Android_Eclipse_Web Services_Ksoap2 - Fatal编程技术网

Java 无法在android中检索web方法的响应

Java 无法在android中检索web方法的响应,java,android,eclipse,web-services,ksoap2,Java,Android,Eclipse,Web Services,Ksoap2,我正在使用KSOAP调用一个web服务。web方法工作正常,它返回字符串为“无效”或“有效”。我试图传入从文本字段中获取的用户名和密码,并获取有效或无效的响应。我没有发现任何错误。我已经对代码进行了注释,显示了日志cat中打印的内容和未打印的内容。我从web方法获得响应的方式有问题。我做错了什么?请帮忙 public class Login extends Activity{ private static final String SOAP_ACTION = "http://tempuri.

我正在使用KSOAP调用一个web服务。web方法工作正常,它返回字符串为“无效”或“有效”。我试图传入从文本字段中获取的用户名和密码,并获取有效或无效的响应。我没有发现任何错误。我已经对代码进行了注释,显示了日志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();
}
 }
公共类登录扩展活动{
私有静态最终字符串SOAP_ACTION=”http://tempuri.org/checkLogin";
私有静态最终字符串操作\u NAME=“checkLogin”;
私有静态最终字符串WSDL\u TARGET\u NAMESPACE=”http://tempuri.org/";
私有静态最终字符串SOAP_地址=”http://10.0.2.2:54714/WebSite1/Service.asmx";
公共静态最终字符串PREFS\u NAME=“MyPrefsFile”;
私有静态最终字符串PREF_USERNAME=“USERNAME”;
私有静态最终字符串PREF_PASSWORD=“PASSWORD”;
按钮sqllogin;
EditText-sqlusername,sqlpassword;
文本视图tvData1;
复选框cb;
@凌驾
创建时受保护的void(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=(按钮)findviewbyd(R.id.bLogin);
cb=(复选框)findViewById(R.id.cbrememberme);
sqllogin.setOnClickListener(新视图.OnClickListener(){
公共void onClick(视图v){
开关(v.getId()){
案例R.id.bLogin:
新建LongOperation()。执行(“”);
打破
} 
}
});
}
私有类LongOperation扩展了异步任务{
@凌驾
受保护的字符串doInBackground(字符串…参数){
字符串username=sqlusername.getText().toString();
字符串密码=sqlpassword.getText().toString();
SoapObject请求=新的SoapObject(WSDL\u目标\u命名空间、操作\u名称);
Request.addProperty(“uname”,String.valueOf(username));
Request.addProperty(“pwd”,String.valueOf(password));
SoapSerializationEnvelope=新的SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet=true;
envelope.setOutputSoapObject(请求);
HttpTransportSE httpTransport=新的HttpTransportSE(SOAP\U地址);
Log.d(“工作”、“工作”);//日志cat中仅显示此日志消息
试试{
调用(SOAP_操作,信封);
对象响应=envelope.getResponse();
字符串结果=response.toString();
Log.d(“res”,result);//这不会显示在Log cat中
if(result.equals(“valid”))
{
Log.d(“是”、“是”);//这不会显示在Log cat中
返回“有效”;
}
else if(result.equals(“无效”))
{
Log.d(“否”、“否”);//这不会显示在Log cat中
返回“无效”;
}
}
捕获(例外e){
e、 printStackTrace();
}
返回null;
}
@凌驾
受保护的void onPostExecute(字符串结果){
Log.d(“tag”、“onpost”);//这不会显示在Log cat中
如果(结果!=null)
{
if(result.equals(“valid”))
{
tvData1.setText(“您已成功登录”);
Intent openhomepage=newintent(“com.android.disasterAlertApp.HOME”);
startActivity(openhomepage);
}
else if(result.equals(“无效”))
{
tvData1.setText(“无效的用户名或密码”);
}
}
其他的
{
Toast.makeText(Login.this,“something short”,Toast.LENGTH_LONG.show();
}
}

我发现了问题所在

而不是

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

        httptransport.call(SOAP_ACTION, envelope);
        SoapPrimitive resultstring = (SoapPrimitive) soapenvelope
                        .getResponse();